0

I'm a beginner in django, I follow the steps showed at GitHub, but I just got a blank page, here my code:

views.py

from django.shortcuts import render
from django_ajax.decorators import ajax
@ajax
def AjaxView(request):
    return render(request, 'blogs/ajaxtest.html'`

urls.py

from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
url(r'^ajax/', 'blogs.views.AjaxView', name='Ajax'))  

ajaxtest.html

<head>
    <script type="text/javascript" src="{% static '/blogs/django_ajax/js/jquery.ajax.min.js' %}"></script>
    <script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
    <title>Ajax Test</title>
</head>
<body>
    <script type="text/javascript">
    ajaxGet('/', function(content){
        //onSuccess
        alert(content);
    })
    </script>
</body>
2
  • You should really accept the answer provided by Adrian.
    – alecxe
    Nov 17, 2014 at 6:16
  • can u post the corrected version for my reference...thanks...
    – Héléna
    Oct 23, 2015 at 8:59

1 Answer 1

2

You need to include jQuery before django_ajax or django_ajax won't work, it is a requirement. Also your AjaxView function seems to be incomplete.

1
  • Thanks, Adrian. It works.but I also forgot to load static files.
    – zl2003cn
    Sep 16, 2014 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.