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.


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


<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;;&gt;google&lt;/a&gt;

How could I achieve this?


Comment posted by……