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
<script>alert("one")</script>, <b>bold</b>, 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). Useescapeseqwhen you have a sequence of potentially unsafe strings that you need to escape before joining or further processing.See also:
escape,safeseq.