Installing Dajax1. Install dajax sudo python setup.py install or sudo easy_install dajax 2. Add 'dajax' in your project settings.py inside INSTALLED_APPS Ej: INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'dajax',
...
)
And ensure that TEMPLATE_LOADERS, looks like the following. Probably you need to uncomment the last line. TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',
'django.template.loaders.eggs.load_template_source',
) 3. Create a new var named DAJAX_MEDIA_PREFIX with the prefix you want to store de ajax functions. DAJAX_MEDIA_PREFIX="dajax" # Will create http://yourdomain.com/dajax/... 4. Add a new line in urls.py with this code: (r'^%s/' % settings.DAJAX_MEDIA_PREFIX, include('dajax.urls')), 5. Create a file named 'ajax.py' inside any django app 6. Inside this file create as many as your want ajax functions. Ej: from dajax.core import Dajax
def assign_test(request):
dajax = Dajax()
dajax.assign('#block01 li','innerHTML','Something else...')
return dajax7. In your settings.py create a new var named DAJAX_FUNCTIONS , this list will contain the name of all ajax-like callable methods. Ej: DAJAX_FUNCTIONS = (
'foo.ajax.assign_test',
...
) 8. The default JS Framework is Prototype, if you want to use jQuery, mootools or dojo set DAJAX_JS_FRAMEWORK DAJAX_JS_FRAMEWORK = "jQuery" or DAJAX_JS_FRAMEWORK = "Mootols" or DAJAX_JS_FRAMEWORK = "Dojo" 9. In your template base load dajax_templatetags : {% load dajax_templatetags %}An include the following code inside the header html block. {% dajax_js_import %}And ensure that your javascript framwork was included too above (In this case Prototype) <script type="text/javascript" src="/static/prototype.js"></script> 10. Now you can invoque your ajax methods using Dajax.foo_assign_test(), foo will be the name of the package containing ajax.py Ej: onclick="Dajax.foo_assign_test();" 11. Enjoy ! ;-)
|