Skip to content

Jinja2 Filters

Filters let you transform values at render time.

Syntax:

html
{{ value | filter_name }}
diagram escaping, and the two ways to switch it off mermaid
With autoescaping on, a value containing markup is neutralised on the way into the page. There are exactly two ways to bypass that -- the safe filter in the template and Markup() in Python -- and both mean you are promising the string is trustworthy. Applying either to something a user typed is how cross-site scripting happens.
html
<p>{{ username | lower }}</p>
<p>{{ username | upper }}</p>
<p>{{ items | join(", ") }}</p>
html
<p>{{ bio | default("No bio yet") }}</p>
html
<p>Count: {{ items | length }}</p>

|safe tells Jinja “don’t escape this value”.

Only use it if you’re absolutely sure the HTML is trusted.

Never mark raw user input as safe.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading