The autoescape tag controls HTML escaping for a template block. Django normally transforms characters such as <, >, and other HTML-sensitive data before rendering it. section 3.7
Use block-level control when a template needs a deliberate exception:
- {% autoescape off %} disables automatic escaping until {% endautoescape %}. section 3.7
- The safe filter, mark_safe(), and format_html() can mark rendered values as safe; use them only when the HTML is intended. section 3.7
Rendering escaped and unescaped instrument names
A value of <b>sax</b> renders as <b>sax</b> normally, but appears as <b>sax</b> inside an autoescape-off block. The same experiment shows safe values such as drum<br/> and formatted big <i>bass</i> remaining HTML. section 3.7
I love the sound a {{ instrument }} makes.
A shiny {{ instrument | safe }} is good.
{% autoescape off %}
Don't put a {{ instrument }} too close to your ear.
{% endautoescape %}
Inspect the compact template showing ordinary interpolation, the safe filter, and an autoescape-off block. section 3.7
