[Fixed]-How do you mark strings as "Safe" in a view (or the template) in Jinja2?

10👍

Use the Markup class:

class jinja2.Markup([string])

Marks a string as being safe for inclusion in HTML/XML output without needing to be escaped.

👤ars

15👍

Check SafeString, like for example:

from django.utils.safestring import SafeString
...
return context.update({
        'html_string': SafeString(html_string),
})

Leave a comment