Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting HTML code with Flask [duplicate]

Tags:

python

html

flask

Currently I have this code

boldtext = "<b>I'm bolded!<b>"

@app.route('/')
def index():
     return render_template("index.html", boldtext=boldtext)

and then in my index.html, I have a section of code with {{ boldtext }} in it.

I had thought that once the page loaded I would see this:

I'm bolded!

Instead I see this:

<b>I'm bolded!<b>

Is there anyway for me to pass actual HTML code to the index.html rather than a snippet of just text?

like image 225
Oscar W Avatar asked Jun 15 '26 08:06

Oscar W


1 Answers

You're looking for the safe filter.

{{ boldtext|safe }}
like image 62
dirn Avatar answered Jun 17 '26 22:06

dirn