Skip to main content

Powerful and easy AJAX framework for django applications.

Project description

Fast and easy AJAX libraries for django applications.

Master Build Status PYPI Package PYPI Status PYPI License



Install django-ajax in your python environment

1- Download and install package:

$ pip install djangoajax

Through Github:

pip install -e git://

or simply with:

$ python install

2- Add 'django_ajax' into the INSTALLED_APPS list.

3- Read usage section and enjoy its advantages!


@ajax Decorator

from django_ajax.decorators import ajax

def my_view(request):

When nothing is returned as result of view then returns (JSON format):

{"status": 200, "statusText": "OK", "content ": null}

Sending custom data in the response

def my_view(request):
    c = 2 + 3
    return {'result': c}

The result is send to the browser in the following way (JSON format)

{"status": 200, "statusText": "OK", "content": {"result": 5}}

Combining with others decorators

from django.contrib.auth.decorators import login_required
from django_ajax.decorators import ajax

def my_view(request):
    # if the request.user is anonymous then this view not proceed
    return {'user_id':}

The JSON response:

{"status": 302, "statusText": "FOUND", "content": "/login"}

Template response

from django.shortcuts import render
from django_ajax.decorators import ajax

def my_view(request):
    return render(request, 'home.html')

The JSON response:

{"status": 200, "statusText": "OK", "content": "<html>...</html>"}

Catch exceptions

def my_view(request):
    a = 23 / 0  # this line throws an exception
    return a

The JSON response:

{"status": 500, "statusText": "INTERNAL SERVER ERROR", "content": "integer division or modulo by zero"}


If you use AJAX quite frequently in your project, we suggest using the AJAXMiddleware described below.

Add django_ajax.middleware.AJAXMiddleware into the MIDDLEWARE_CLASSES list in

All your responses will be converted to JSON if the request was made by AJAX, otherwise is return a HttpResponse.


If you use this middleware cannot use @ajax decorator.

AJAXMixin for class-based views

AJAXMixin is an object that calls the AJAX decorator.

from django.views.generic import TemplateView
from django_ajax.mixin import AJAXMixin

class SimpleView(AJAXMixin, TemplateView):
    template_name = 'home.html'

The JSON response:

{"status": 200, "statusText": "OK", "content": "<html>...</html>"}


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for djangoajax, version 3.0
Filename, size File type Python version Upload date Hashes
Filename, size djangoajax-3.0-py3.6.egg (35.9 kB) File type Egg Python version 3.6 Upload date Hashes View
Filename, size djangoajax-3.0.tar.gz (17.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page