Fast and easy AJAX libraries for django applications. Contains ajax decorator, ajax middleware, shortcuts and more.

yceruto yceruto Last update: Jan 18, 2024

django-ajax

Fast and easy AJAX libraries for django applications.

Master Build Status

PYPI Package

PYPI Status

PYPI License

Requirements

3.x

2.x

Installation

Install django-ajax in your python environment

1- Download and install package:

Through Github:

or simply with:

2- Add 'django_ajax' into the INSTALLED_APPS list.

3- Read usage section and enjoy this feature!

Usage

@ajax Decorator

When the view does not return anything, you will receive this response (JSON format):

Sending content

The whole result is converted into a JSON format as part of the content element:

Combining with others decorators

The location or path of the redirection response will be given in the content item, also the status and statusText will reflect what is going on:

Template response

The JSON response:

Catch exceptions

The JSON response:

AJAXMiddleware

If you are using AJAX at all times in your project, we suggest you activate the AJAXMiddleware described below.

Add django_ajax.middleware.AJAXMiddleware to the MIDDLEWARE_CLASSES list in settings.py and all your responses will be converted to JSON whereas the request was made via AJAX, otherwise it will return a normal HttpResponse.

Caution

If this middleware is activated you cannot use the @ajax decorator. That will cause double JSON conversion.

AJAXMixin for class-based views

AJAXMixin is an object that call to AJAX decorator.

The JSON response:

Enjoy And Share!

Subscribe to our newsletter