safeseq Filter

Data Structure

Documentation

Applies the safe filter to each element of a sequence.

Variable

poem_lines = [
    'Much to his Mum and Dad’s dismay,',
    'Horace ate himself one day.',
    'He didn’t stop to say his grace,',
    'He just sat down and ate his face.',
    '“We can’t have this!” His Dad declared,',
    '“If that lad’s ate, he should be shared.”'
]

Template

{{ poem_lines|safeseq|join:'<br>' }}

Result

Much to his Mum and Dad’s <em>dismay</em>,<br>Horace <strong>ate himself</strong> one day.<br>He <em>didn’t stop</em> to say his grace,<br>He just sat down and <strong>ate his face</strong>.<br><em>“We can’t have this!”</em> His Dad declared,<br>“If that lad’s ate, <strong>he should be shared</strong>.”

And the output to the browser looks like this:

Much to his Mum and Dad’s dismay,
Horace ate himself one day.
He didn’t stop to say his grace,
He just sat down and ate his face.
“We can’t have this!” His Dad declared,
“If that lad’s ate, he should be shared.”


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

Send Feedback

Official Documentation
This page last updated on Sept. 16, 2020, 7:34 p.m. EST