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.
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:
<a href="google.com">google</a>
How could I achieve this?