John
John

Reputation: 4038

Jinja2 to display image in browser

mymodel.url is textproperty(string) which is something like this

<a href ='http://www.abc.com'><img src='http://xyz.com/></a><img src="http://www.abcdefd.com" /> 

In index.html, if I use {{mymodel.url}}, I will see the html code in my browser. In otherwords, jinja2 consider {{mymodel.url}} as string.

<a href ='http://www.abc.com'><img src='http://xyz.com/></a><img src="http://www.abcdefd.com" /> 

I want to see the image in my browser. How can I do it?

Upvotes: 2

Views: 1012

Answers (1)

Paul Collingwood
Paul Collingwood

Reputation: 9116

You have to indicate to jinja2 that this content is "safe" to display in a browser as HTML

{{mymodel.url|safe }}

HTML Escaping

When generating HTML from templates, there’s always a risk that a variable will include characters that affect the resulting HTML. There are two approaches: manually escaping each variable or automatically escaping everything by default.

Upvotes: 1

Related Questions