Menu Close

How to render a template variable as HTML with Python Django?

To render a template variable as HTML with Python Django, we can use autoescape off or safe.

For instance, we write

{{ myhtml |safe }}

to use the safe filter to render myhtml as HTML.

Or we use

{% autoescape off %}
    {{ myhtml }}
{% endautoescape %}

to use the autoescape off to render myhtml as HTML.

Posted in Python, Python Answers