-1

I have the following Python code

...
return render_template('main.html', in_html = in_html)

in_html is html code that I want to run in a div once main.html loads

My main.html file

...
<div> {{in_html}} </div>

This doesn't work, it displays the actual html code as text of the div. What am I doing wrong?

robo-monk
  • 134
  • 3
  • 9

1 Answers1

2

Write {{ in_html|safe }} to indicate that in_html is safe to render as HTML.

Alternatively, use MarkUp when passing the value to the template from Python:

from flask import Markup

def foo():
    # ...
    return render_template('main.html', in_html = MarkUp(in_html))
kaya3
  • 47,440
  • 4
  • 68
  • 97