Categories
Python Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *