escape Filter

Coding

Documentation

Escapes HTML characters.

Variable

blurb = '<p>You are <em>pretty</em> smart!</p>'

Template

{% autoescape off %}
  <code>{{ blurb|escape }}</code> will output:
  {{ blurb }}
{% endautoescape %}

Result

<code>&lt;p&gt;You are &lt;em&gt;pretty&lt;/em&gt; smart!&lt;/p&gt;</code> will output:
<p>You are <em>pretty</em> smart!</p>

The browser output would be:

<p>You are <em>pretty</em> smart!</p> will output:

You are pretty smart!

The escape filter is only relevant if autoescaping is off.


Did we get something wrong? Is there a use case for the escape filter that we should add? Please let us know.

Send Feedback

Official Documentation
This page last updated on Oct. 30, 2022, 1:21 p.m. EST