Home > Net >  How to write Inner HTML with Flask?
How to write Inner HTML with Flask?

Time:08-10

I need to add some text in a HTML file, using Flask, with HTML tags enabled. If the HTML file looks like {{name}}, I can use flask like this:

@app.route('/')
def main():
    return render_template('template.html', name='name')

However, if I try the code below, the text between the <b> tag isn't bold.

@app.route('/')
def main():
    return render_template('template.html', name='<b>name</b>')

How can I change this?

CodePudding user response:

You could try using

{{ name | safe }}

Is there a reason you can't / don't want to do <b>{{ name }}</b>? Do you want different formatting depending on the name? In the case you could also use css and classes that depend on the name.

  • Related