diff options
| author | Hrushikesh Vaidya <hrushikeshrv@gmail.com> | 2022-06-28 10:30:39 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-06-28 11:35:41 +0200 |
| commit | e40b77365fb030b66c039a263ae9fd262a59e373 (patch) | |
| tree | c741d705d2f6e6c742dbaa4917ae8f8a140c89a1 | |
| parent | aed1a73e0a848c5368abe57a6b57119acfdbbd67 (diff) | |
[4.1.x] Refs #33779 -- Doc'd django.utils.html.json_script().
Backport of 0ee03a439b7016c068ab2e0c477d5c84f750a82c from main
| -rw-r--r-- | docs/ref/utils.txt | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/docs/ref/utils.txt b/docs/ref/utils.txt index 7712015929..6b44e81611 100644 --- a/docs/ref/utils.txt +++ b/docs/ref/utils.txt @@ -655,6 +655,20 @@ escaping HTML. ((u.first_name, u.last_name) for u in users) ) +.. function:: json_script(value, element_id=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 + ``<script>`` tag. If the ``element_id`` parameter is not ``None``, the + ``<script>`` tag is given the passed id. For example:: + + >> json_script({"hello": "world"}, element_id="hello-data") + '<script id="hello-data" type="application/json">{"hello": "world"}</script>' + + .. versionchanged:: 4.1 + + In older versions, the ``element_id`` argument was required. + .. function:: strip_tags(value) Tries to remove anything that looks like an HTML tag from the string, that |
