Skip to content

Jinja2 Filters

Filters let you transform values at render time.

Syntax:

html
{{ value | filter_name }}
html
{{ value | filter_name }}

Common built-in filters

html
<p>{{ username | lower }}</p>
<p>{{ username | upper }}</p>
<p>{{ items | join(", ") }}</p>
html
<p>{{ username | lower }}</p>
<p>{{ username | upper }}</p>
<p>{{ items | join(", ") }}</p>

Default values

html
<p>{{ bio | default("No bio yet") }}</p>
html
<p>{{ bio | default("No bio yet") }}</p>

length

html
<p>Count: {{ items | length }}</p>
html
<p>Count: {{ items | length }}</p>

Important security note: safe

|safe|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.

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did