Categories
Python Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *