Ask coding questions

← Back to all posts
How do I use a flask variable as HTML code
Subscribe2

So I have a flask code

it goes as follows
Main.py:

a = "<div class="keyword"> Hello </div>"
return render_template("index.html", myvar = a)

HTML:

<html> <body> {{ myvar }} </body> </html>

it shows my var as a string, I want myvar to be added to the site as html

Answered by IMayBeMe [earned 5 cycles]
View Answer
Voters
Subscribe2
Comments
hotnewtop
IMayBeMe

Just do {{myvar | safe}}. It should fix the issue