Other Goodies¶
AjaxResponse
¶
-
class
django_goodies.misc.
AjaxResponse
(request, data=None, success=None, **kwargs)[source]¶ New in version 0.4.
An extension of Django’s JsonResponse
, differing in the following ways:
The
data
argument is optional. If provided, it must always be adict
instance. If not provided, a newdict
instance will be created and used. Using thesafe
argument ofJsonResponse
to JSON-encode other types is not supported (see the documentation for thesafe
argument ofJsonResponse
).The first positional argument should be a Django
HttpRequest
instance, used to retrieve messages from the Django message framework store and add them to thedata
dictionary 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
success
can be set to add a “success” key to thedata
dictionary. 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, AjaxResponse
accepts and supports all arguments of JsonResponse
.