mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #33779 -- Allowed customizing encoder class in django.utils.html.json_script().
This commit is contained in:
committed by
Mariusz Felisiak
parent
0ee03a439b
commit
72e41a0df6
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user