Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

Template Filter - escape


Example

Display a text containing HTML, with and without escape:

{% autoescape off %}
  <h1>{{ heading|escape }}</h1>
  <h1>{{ heading }}</h1>
{% endautoescape %}
Run Example »

Definition and Usage

The escape filter escapes HTML characters from the value.

Note: Escaping HTML characters is a default setting in Django, so we have to turn off autoescape in the example to be able to see the difference.

These characters are escaped:

  • < is converted to &lt;
  • > is converted to &gt;
  • ' is converted to '
  • " is converted to "
  • & is converted to &amp;

Syntax

Template filters are defined by using a pipe | character followed by the name of the filter.

{{ value|escape }}