How to have a Dajaxice ajax.py file for common ajax calls across a Django project
Is it possible to have a Dajaxice ajax.py file in the root directory of a Django project that handles ajax calls co开发者_如何学JAVAmmon to more than one app. In other words, an ajax.py file outside of a particular app.
Thanks
If you want to share common functions, you can have them eiter in a ajax.py of a specififc application and import them from the other applications or have it in the root directory and import it from there:
DJANGODIR/ajax.py:
from django.utils import simplejson
def helloworld(request, name, id):
return simplejson.dumps({'message':'hello %s' % name})
DJANGODIR/my_app/ajax.py:
from DJANGODIR.ajax import helloworld
from dajaxice.core import dajaxice_functions
dajaxice_functions.register(helloworld)
精彩评论