Menu Close

How to escape jinja2 syntax in a jinja2 template with Python Flask?

Sometimes, we want to escape jinja2 syntax in a jinja2 template with Python Flask.

In this article, we’ll look at how to escape jinja2 syntax in a jinja2 template with Python Flask.

How to escape jinja2 syntax in a jinja2 template with Python Flask?

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.

For instance, we write

{% raw %}

Anything in this block is treated as raw text,
including {{ curly braces }} and
{% block %}

{% endraw %}

to treat

Anything in this block is treated as raw text,
including {{ curly braces }} and
{% block %}

as raw text.

Conclusion

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.

Posted in Python, Python Answers