Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

autoescape Template Tag


Example

Escape variables that contain HTML tags:

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

Definition and Usage

The autoescape tag is used to specify if autoescape is on or off.

If autoescape is on, which is default, HTML code in variables will be escaped.

When escape is on, these characters are escaped:

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

Example

With autoescape on, any HTML elements inside variables will be converted according to the list above.

{% autoescape on %}
  <h1>{{ heading }}</h1>
{% endautoescape %}
Run Example »

Syntax

{% autoescape on|off %}
  ...
{% endautoescape %}

Parameters

Value Description
on Default. Specifies that the block will be escaped
off Specifies that the block will not be escaped