AJAX¶
ajax_login_required¶
New in version 0.7.
AjaxResponse¶
-
class
djem.ajax.AjaxResponse(request, data=None, success=None, **kwargs)[source]¶ An extension of Django’s
JsonResponse, differing in the following ways:The
dataargument is optional. If provided, it must always be adictinstance. If not provided, a newdictinstance will be created and used. Using thesafeargument ofJsonResponseto JSON-encode other types is not supported (see the documentation for thesafeargument ofJsonResponse).The first positional argument should be a Django
HttpRequestinstance, used to retrieve messages from the Django message framework store and add them to thedatadictionary under the “messages” key. The messages are added as a list of dictionaries containing:- message: The message string.
- tags: A string of the tags applied to the message, space separated.
The optional argument
successcan be set to add a “success” key to thedatadictionary. The “success” key will always be added as a boolean value, regardless of what was passed (though it will not be added at all if nothing was passed).
With the exception of
safe, as noted above,AjaxResponseaccepts and supports all arguments ofJsonResponse.To help prevent XSS vulnerabilities, the messages from the Django messages framework that are included in the response are automatically escaped. If a message should legitimately contain HTML, it can be marked as safe to prevent it being escaped.
See also
MessageMiddleware- A replacement for Django’s own
MessageMiddlewarethat avoids simultaneous requests interfering with each other’s message stores - an issue made more likely when making use of AJAX.