summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorHrushikesh Vaidya <hrushikeshrv@gmail.com>2022-06-23 14:20:20 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-06-28 10:54:38 +0200
commit72e41a0df6db23410135364223eeda83ac2a8b27 (patch)
tree4c173f6eae2977140cf30bb1f1c10ab9c623c044 /docs
parent0ee03a439b7016c068ab2e0c477d5c84f750a82c (diff)
Fixed #33779 -- Allowed customizing encoder class in django.utils.html.json_script().
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/utils.txt11
-rw-r--r--docs/releases/4.2.txt3
2 files changed, 12 insertions, 2 deletions
diff --git a/docs/ref/utils.txt b/docs/ref/utils.txt
index 6b44e81611..d296d2bda1 100644
--- a/docs/ref/utils.txt
+++ b/docs/ref/utils.txt
@@ -655,7 +655,7 @@ escaping HTML.
((u.first_name, u.last_name) for u in users)
)
-.. function:: json_script(value, element_id=None)
+.. function:: json_script(value, element_id=None, encoder=None)
Escapes all HTML/XML special characters with their Unicode escapes, so
value is safe for use with JavaScript. Also wraps the escaped JSON in a
@@ -665,10 +665,19 @@ escaping HTML.
>> json_script({"hello": "world"}, element_id="hello-data")
'<script id="hello-data" type="application/json">{"hello": "world"}</script>'
+ The ``encoder``, which defaults to
+ :class:`django.core.serializers.json.DjangoJSONEncoder`, will be used to
+ serialize the data. See :ref:`JSON serialization
+ <serialization-formats-json>` for more details about this serializer.
+
.. versionchanged:: 4.1
In older versions, the ``element_id`` argument was required.
+ .. versionchanged:: 4.2
+
+ The ``encoder`` argument was added.
+
.. function:: strip_tags(value)
Tries to remove anything that looks like an HTML tag from the string, that
diff --git a/docs/releases/4.2.txt b/docs/releases/4.2.txt
index ca1c2a0eaa..649fb797c6 100644
--- a/docs/releases/4.2.txt
+++ b/docs/releases/4.2.txt
@@ -214,7 +214,8 @@ URLs
Utilities
~~~~~~~~~
-* ...
+* The new ``encoder`` parameter for :meth:`django.utils.html.json_script`
+ function allows customizing a JSON encoder class.
Validators
~~~~~~~~~~