force_escape Filter

Coding

Documentation

Almost identical to escape, and you almost definitely want to use escape instead.

Variable

shopping_list = '''Carrots
Honey
Milk
Butter'''

Template with force_escape

{% autoescape off %}
    {{ shopping_list|linebreaks|force_escape }}
{% endautoescape %}

Result

<p>Carrots<br>Honey<br>Milk<br>Butter</p>

Template with escape

{% autoescape off %}
    {{ shopping_list|linebreaks|escape }}
{% endautoescape %}

Result with escape

<p>Carrots<br>Honey<br>Milk<br>Butter</p>

Notice that the <br> tags that are generated with the linebreaks filter are escaped when force_escape is used, but not when escape is used.

Commentary

You are very unlikely to need this.


Did we get something wrong? Is there a use case for the force_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