You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/nonce.rst
+41-7Lines changed: 41 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,13 +42,32 @@ This library contains an optional context processor, adding ``csp.context_proces
42
42
43
43
.. note::
44
44
45
-
If you're making use of ``csp.extensions.NoncedScript`` you need to have ``jinja2>=2.9.6`` installed, so please make sure to either use ``django-csp[jinja2]`` in your requirements or define it yourself.
45
+
If you're making use of ``csp.extensions.NoncedScript`` you need to have ``jinja2>=2.9.6`` installed, so please make sure to either use ``django-csp[jinja2]`` in your requirements or define it yourself.
46
46
47
-
Since it can be easy to forget to include the ``nonce`` property in a script tag, there is also a ``script`` template tag available for both Django templates and Jinja environments.
47
+
48
+
It can be easy to forget to include the ``nonce`` property in a script tag, so there is also a ``script`` template tag available for both Django templates and Jinja environments.
48
49
49
50
This tag will output a properly nonced script every time. For the sake of syntax highlighting, you can wrap the content inside of the ``script`` tag in ``<script>`` html tags, which will be subsequently removed in the rendered output. Any valid script tag attributes can be specified and will be forwarded into the rendered html.
50
51
51
-
Django:
52
+
53
+
Django Templates
54
+
----------------
55
+
56
+
Add the CSP template tags to the TEMPLATES section of your settings file:
57
+
58
+
.. code-block:: python
59
+
60
+
TEMPLATES= [
61
+
{
62
+
"OPTIONS": {
63
+
'libraries': {
64
+
'csp': 'csp.templatetags.csp',
65
+
}
66
+
},
67
+
}
68
+
]
69
+
70
+
Then load the ``csp`` template tags and use ``script`` in the template:
52
71
53
72
.. code-block:: jinja
54
73
@@ -60,9 +79,24 @@ Django:
60
79
{% endscript %}
61
80
62
81
63
-
Jinja:
82
+
Jinja
83
+
-----
84
+
85
+
Add ``csp.extensions.NoncedScript`` to the TEMPLATES section of your settings file:
0 commit comments