summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorSambhav Satija <sambhav13085@iiitd.ac.in>2015-08-12 06:23:26 +0530
committerTim Graham <timograham@gmail.com>2015-08-12 10:39:07 -0400
commitd0bd5330432e1dda519ebd89606bd0980a36dcb4 (patch)
treed40cb0e19bb24c43e5f4c67b47b171b45f240e29 /django
parent290145e6616b32a0b0c63f44b7c09d0a4af7dfd5 (diff)
Fixed #25254 -- Added JsonResponse json_dumps_params parameter.
Diffstat (limited to 'django')
-rw-r--r--django/http/response.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/django/http/response.py b/django/http/response.py
index aece5ec5a6..b42f0b51d3 100644
--- a/django/http/response.py
+++ b/django/http/response.py
@@ -492,12 +492,16 @@ class JsonResponse(HttpResponse):
``django.core.serializers.json.DjangoJSONEncoder``.
:param safe: Controls if only ``dict`` objects may be serialized. Defaults
to ``True``.
+ :param json_dumps_params: A dictionary of kwargs passed to json.dumps().
"""
- def __init__(self, data, encoder=DjangoJSONEncoder, safe=True, **kwargs):
+ def __init__(self, data, encoder=DjangoJSONEncoder, safe=True,
+ json_dumps_params=None, **kwargs):
if safe and not isinstance(data, dict):
raise TypeError('In order to allow non-dict objects to be '
'serialized set the safe parameter to False')
+ if json_dumps_params is None:
+ json_dumps_params = {}
kwargs.setdefault('content_type', 'application/json')
- data = json.dumps(data, cls=encoder)
+ data = json.dumps(data, cls=encoder, **json_dumps_params)
super(JsonResponse, self).__init__(content=data, **kwargs)