diff --git a/django/http/response.py b/django/http/response.py index 29d0ea6aba87..c4ed51206089 100644 --- a/django/http/response.py +++ b/django/http/response.py @@ -749,7 +749,7 @@ class JsonResponse(HttpResponse): :param encoder: Should be a json encoder class. Defaults to ``django.core.serializers.json.DjangoJSONEncoder``. :param safe: Controls if only ``dict`` objects may be serialized. Defaults - to ``True``. + to ``False``. :param json_dumps_params: A dictionary of kwargs passed to json.dumps(). """ @@ -757,7 +757,8 @@ def __init__( self, data, encoder=DjangoJSONEncoder, - # RemovedInDjango71Warning: Remove the safe parameter. + # RemovedInDjango71Warning: Remove the safe parameter from here and + # the docstring. safe=None, json_dumps_params=None, **kwargs, diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt index dcb6a8b057dd..5469562a2d9f 100644 --- a/docs/ref/request-response.txt +++ b/docs/ref/request-response.txt @@ -1222,7 +1222,7 @@ can create it with the help of :class:`http.HTTPStatus`. For example:: ``JsonResponse`` objects ======================== -.. class:: JsonResponse(data, encoder=DjangoJSONEncoder, safe=True, json_dumps_params=None, **kwargs) +.. class:: JsonResponse(data, encoder=DjangoJSONEncoder, safe=False, json_dumps_params=None, **kwargs) An :class:`HttpResponse` subclass that helps to create a JSON-encoded response. It inherits most behavior from its superclass with a couple @@ -1239,7 +1239,7 @@ can create it with the help of :class:`http.HTTPStatus`. For example:: serialize the data. See :ref:`JSON serialization ` for more details about this serializer. - The ``safe`` boolean parameter defaults to ``True``. If it's set to + The ``safe`` boolean parameter defaults to ``False``. 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 the first argument, a :exc:`TypeError` will be raised. @@ -1247,6 +1247,14 @@ can create it with the help of :class:`http.HTTPStatus`. For example:: The ``json_dumps_params`` parameter is a dictionary of keyword arguments to pass to the ``json.dumps()`` call used to generate the response. +.. versionchanged:: 6.2 + + In earlier versions, the ``safe`` parameter defaulted to ``True``. + +.. deprecated:: 6.2 + + The ``safe`` parameter is deprecated. + Usage ----- @@ -1278,10 +1286,6 @@ using non-dict objects in JSON-encoded responses. other objects besides dictionaries, as the (now deprecated) ``safe`` parameter defaulted to ``True``, raising :exc:`TypeError`. -.. deprecated:: 6.2 - - The ``safe`` parameter is deprecated. - Changing the default JSON encoder ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~