JsonResponse Objects
class JsonResponse(data, encoder=DjangoJSONEncoder, safe=True, **kwargs)
An HttpResponse
subclass that helps to create a JSON-encoded response. It inherits most behavior from its superclass with some differences:
- Its default
Content-Type
header is set toapplication/json
. - The first parameter,
data
, should be adict
instance. If thesafe
parameter is set toFalse
(see below) it can be any JSON-serializable object. - The
encoder
, which defaults todjango.core.serializers.json.DjangoJSONEncoder
, will be used to serialize the data.
The safe
boolean parameter defaults to True
. If it's set to False
, any object can be passed for serialization (otherwise only dict
instances are allowed). If safe
is True
and a non-dict
object is passed as ...
Get Mastering Django: Core now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.