I am stuck trying to create a simple application with dajaxice. I read all the topics about this problem here, and here you not only rewrite all the code many times, but you also donβt see what the problem is. the most interesting thing is that these examples work (almost all): https://github.com/jorgebastida/django-dajaxice/downloads dajaxice-examples.tar.gz
But in my project, I have this:
Uncaught TypeError: Cannot call method 'sayhello' of undefined
my tools:
- Windows 7 64
- python 2.7.3
- Django-1.4.2
- Django-dajaxice-0.2
Project Structure:
BlocalProject/ templates/ template_1.html manage.py BlocalProject/ ajapp/ __init__.py ajview.py __init__.py settings.py urls.py views.py wsgi.py
urls.py:
from django.conf.urls.defaults import * import settings from dajaxice.core import dajaxice_autodiscover dajaxice_autodiscover() urlpatterns = patterns('', (r'^%s/' % (settings.DAJAXICE_MEDIA_PREFIX), include('dajaxice.urls')), (r'^$', 'BlocalProject.views.start_page'), )
views.py:
from django.shortcuts import render def start_page(request): return render(request,'template_1.html')
ajapp.py:
from django.utils import simplejson from dajaxice.core import dajaxice_functions def sayhello(request): return simplejson.dumps({'message': 'Trololo!'}) dajaxice_functions.register(sayhello)
template_1.html:
{% load dajaxice_templatetags %} <html> {% dajaxice_js_import %} <script> function alertMessage(data){ alert(data.message); return false; } </script> <body> Some text <input type="button" value="Get!" onclick="Dajaxice.ajapp.sayhello(alertMessage);" /> </body> </html>
settings.py:
# Django settings for BlocalProject project. DEBUG = True TEMPLATE_DEBUG = DEBUG ADMINS = (
source share