Search code examples
djangodajaxicedajax

Django Dajax vs Dajaxice


This may be a very silly question but I'm looking at implementing ajax in my django project and the big plugin seems to be dajax/dajaxice however I can't for the life of me distinguish between the two. Could someone clear this up a little for me? Thanks.


Solution

  • Dajaxice is the core of the project, to quote the website:

    'Its main goal is to trivialize the asynchronous communication between the django server side code and your js code.'

    This means that a django / python method on the server like:

    from django.utils import simplejson
    from dajaxice.decorators import dajaxice_register
    
    @dajaxice_register
    def multiply(request, a, b):
      result = int(a) * int(b)
      return simplejson.dumps({'result' : result})
    

    Can be called on the client using javascript:

    var result = Dajaxice.calcualator.multiply(1, 2);
    console.log("Dajax says 1 * 2 = "+result);
    

    Dajax provides a series of tools that incorporate dajaxice but requires less Javascript to be used, instead relying on more Python. The multiple example is here.

    I have used dajaxice on a few projects without using dajax. Also worth mentioning is Tasty Pie this creates a similar interface on the server, and using JQuery ajax helper functions like .post(), client side, little additional code is required in javascript compared to dajaxice.