Solution 1 :

This arises because Flask will automatically escape any HTML tags contained in your template variables, to avoid common security concerns.

See the documentation for how to disable this – one simple way is to replace {{ text}} with {{ text|safe}}.

But note that you must not do this if the text variable can come from an “unsafe” source, such as an untrusted user.

Problem :

I am using Flask with Jinja2 templating to build a static webpage. I am sourcing page texts from .txt files. What I want to do is to pass literal HTML tags from the .txt file and have it interpreted in the DOM. Currently, the text it represented literally, and if I look at the page source, the tags are interpreted in escape characters.

Text

The map uses the <a href="google.com">Google</a> API.

HTML

<p>{{ text }}</p>  <!-- text above goes here -->

The anchor tag is not represented as an HTML tag, but rather like this:

&lt;a href=&#34;google.com&#34;&gt;google&lt;/a&gt;

How could I achieve this?

Comments

Comment posted by jinja.palletsprojects.com/en/2.11.x/templates/…

jinja.palletsprojects.com/en/2.11.x/templates/…

By