|
@@ -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
|