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?

Oscar W
  • 464
  • 4
  • 17

2 Answers2

3

You're looking for the safe filter.

{{ boldtext|safe }}
dirn
  • 19,454
  • 5
  • 69
  • 74
1

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>")
Oscar W
  • 464
  • 4
  • 17