Menu
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY CYBERSECURITY DATA SCIENCE
     ❯   

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 }}