escapeseq Filter

Coding

Documentation

Applies the escape filter to each element of a sequence.

New in Django 5.0.

Variable

items = [
    '<script>alert("one")</script>',
    '<b>bold</b>',
    'plain text'
]

Template

{{ items|escapeseq|join:", " }}

Result

&lt;script&gt;alert("one")&lt;/script&gt;, &lt;b&gt;bold&lt;/b&gt;, plain text

Each element in the sequence has its HTML characters escaped before being joined.

Use Case

This is useful when you need to join a list of items that may contain HTML, and you want to ensure each item is escaped before joining:

{{ user_comments|escapeseq|join:"<br>" }}

Without escapeseq, you would need to loop through the items manually to escape each one.

Commentary

This filter complements safeseq, which does the opposite (marks each element as safe). Use escapeseq when you have a sequence of potentially unsafe strings that you need to escape before joining or further processing.

See also: escape, safeseq.


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

Send Feedback

Official Documentation
This page last updated on Dec. 3, 2025, 11:36 p.m. EST