forked from orbit-oss/flask
Imply the |safe on tojson in templates and change escaping logic
This commit is contained in:
parent
56d3b74488
commit
ef72b78042
7 changed files with 46 additions and 31 deletions
|
|
@ -63,9 +63,10 @@ like this:
|
|||
$SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
|
||||
</script>
|
||||
|
||||
The ``|safe`` is necessary so that Jinja does not escape the JSON encoded
|
||||
string with HTML rules. Usually this would be necessary, but we are
|
||||
inside a `script` block here where different rules apply.
|
||||
The ``|safe`` is necessary in Flask before 0.10 so that Jinja does not
|
||||
escape the JSON encoded string with HTML rules. Usually this would be
|
||||
necessary, but we are inside a `script` block here where different rules
|
||||
apply.
|
||||
|
||||
.. admonition:: Information for Pros
|
||||
|
||||
|
|
@ -76,6 +77,10 @@ inside a `script` block here where different rules apply.
|
|||
escape slashes for you (``{{ "</script>"|tojson|safe }}`` is rendered as
|
||||
``"<\/script>"``).
|
||||
|
||||
In Flask 0.10 it goes a step further and escapes all HTML tags with
|
||||
unicode escapes. This makes it possible for Flask to automatically
|
||||
mark the result as HTML safe.
|
||||
|
||||
|
||||
JSON View Functions
|
||||
-------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue