Django Unobtrusive Ajax
Python JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


DjangoAjax is the example of unobtrusive ajax call in django, all you need is few additional attributes on the form to make Ajax enabled applications with almost no change in django application

How To

List of ajax attributes:

Ajax Modes

There are three modes for result set to be placed in targeted element, which must be set in data-ajax-mode attribute:

  • Replace: Replace the entire content in targeted element
  • Before: Insert at top in the targeted element
  • After: Insert at the bottom in the targeted element

Ajax Events

Four events are available to subscribe through attributes of Ajax call:

  • data-ajax-begin: fired on the beginning of the request
  • data-ajax-complete: fired on the completion of the request
  • data-ajax-failure: fired on the failure of the request
  • data-ajax-success: fired on the success of the request

Loading Animation

You can set element id the data-ajax-loading="#loading" to display during Ajax call and data-ajax-loading-duration="2000" is the duration for the animation.

Graceful Degradation

Application should be able to handle non Ajax call if javascript is not enabled, so instead of settings ajax url in form’s action, you can set it in data-ajax-url. Alternatively you can also check for ajax call with in view method and act accordingly, for example:

if request.is_ajax():
return HttpResponse(str(

return render_to_response('gettime.html', {'time': str( })