3

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?

0

2 Answers 2

3

You're looking for the safe filter.

{{ boldtext|safe }} 
Sign up to request clarification or add additional context in comments.

Comments

2

Okay I actually figured out an answer to this fairly quickly, I tried it before but it didn't work due to syntax. All I have to do is import Markup by doing.

from flask import Markup 

and then instead of defining boldtext as

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

It's instead

boldtext = Markup("<b>I'm bolded!<b>") 

1 Comment

How can insert variable inside a Markup sir ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.