Can I do it inside the template or must it be done in python code?
I have a variable that may contain da<ngero>u&s chars. How do I escape it in jinja2?
To escape jinja2 syntax in a jinja2 template with Python Flask, we can put render the template code without interpretation by putting the code in the {% raw %} block.
Jinja provides a feature that can be enabled to escape HTML syntax in rendered templates.
Jinja, also commonly referred to as "Jinja2" to specify the newest release version, is a Python template engine used to create HTML, XML or other markup formats that are returned to the user via an HTTP response.
e.g.
{{ user.username|e }}
Pipe it through the |e
filter
Jinja: Template Designer Documentation -> HTML Escaping
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With