Filters transform the value of a variable. Apply them using the pipe symbol (|):
{{ value|filtername }}
{{ value|filtername:argument }}
{{ value|filter1|filter2|filter3 }}Converts a string to uppercase.
{{ "hello"|upper }} {# HELLO #}Converts a string to lowercase.
{{ "HELLO"|lower }} {# hello #}Capitalizes the first character of the string.
{{ "hello world"|capfirst }} {# Hello world #}Converts a string to title case.
{{ "hello world"|title }} {# Hello World #}Centers the value in a field of a given width.
{{ "hi"|center:10 }} {# " hi " #}Left-aligns the value in a field of a given width.
{{ "hi"|ljust:10 }} {# "hi " #}Right-aligns the value in a field of a given width.
{{ "hi"|rjust:10 }} {# " hi" #}Removes all occurrences of a substring.
{{ "hello world"|cut:" " }} {# helloworld #}Truncates a string to the specified number of characters, appending a Unicode
ellipsis (…) if truncated.
{{ "Hello World"|truncatechars:8 }} {# Hello W… #}Like truncatechars, but preserves HTML tags.
{{ "<p>Hello World</p>"|truncatechars_html:8 }} {# <p>Hello W…</p> #}Truncates a string after a specified number of words.
{{ "One two three four five"|truncatewords:3 }} {# One two three … #}Like truncatewords, but preserves HTML tags.
{{ "<p>One two three four five</p>"|truncatewords_html:3 }}
{# <p>One two three …</p> #}Returns the number of words.
{{ "Hello World"|wordcount }} {# 2 #}Wraps text at the specified character column width. Lines are broken at word
boundaries; long words that exceed the width are not split. Existing newlines
are preserved. \r\n and \r are normalized to \n before processing.
Verified against Django 4.2 django.utils.text.wrap().
{{ "a b c d e f g h"|wordwrap:5 }}
{# a b c
d e f
g h #}Adds backslashes before quotes.
{{ "I'm here"|addslashes }} {# I\'m here #}Splits a string into a list.
{% for part in "a,b,c"|split:"," %}{{ part }}{% endfor %}
{# abc #}Converts a string into a list of characters.
{% for char in "hello"|make_list %}{{ char }}-{% endfor %}
{# h-e-l-l-o- #}Converts phone letters to numbers.
{{ "1-800-COLLECT"|phone2numeric }} {# 1-800-2655328 #}Escapes HTML special characters. Applied automatically unless safe is used.
{{ "<script>"|escape }} {# <script> #}Escapes characters for use in JavaScript strings.
{{ "line1\nline2"|escapejs }}Marks a value as safe (not requiring HTML escaping).
{{ trusted_html|safe }}Converts newlines into <p> and <br /> tags.
{{ "Line 1\n\nLine 2"|linebreaks }}
{# <p>Line 1</p>
<p>Line 2</p> #}Converts newlines into <br /> tags.
{{ "Line 1\nLine 2"|linebreaksbr }}
{# Line 1<br />Line 2 #}Removes all HTML tags.
{{ "<p>Hello</p>"|striptags }} {# Hello #}Removes specified HTML tags.
{% autoescape off %}{{ "<p><b>Hello</b></p>"|removetags:"b" }}{% endautoescape %} {# <p>Hello</p> #}Adds line numbers to each line.
{{ "Line 1\nLine 2"|linenumbers }}
{# 1. Line 1
2. Line 2 #}Converts URLs and email addresses in text into clickable links.
{{ "Visit https://example.com"|urlize }}
{# Visit <a href="https://example.com" rel="nofollow">https://example.com</a> #}Like urlize, but truncates URLs longer than the given limit.
{{ "Visit https://example.com/very/long/path"|urlizetrunc:20 }}Encodes an IRI (Internationalized Resource Identifier) using Go's url.QueryEscape
for non-IRI characters. IRI-safe characters (/#%[]=:;$&()+,!?*@'~) are preserved.
Django difference: Django's
iri_to_uri()encodes spaces as%20. Go'surl.QueryEscapeencodes spaces as+.
{{ "path/to file"|iriencode }} {# path/to+file #}URL-encodes a string using Go's url.QueryEscape.
Django difference: Django uses
%20for spaces and preserves/. Go'surl.QueryEscapeuses+for spaces and encodes/as%2F.
{{ "hello world"|urlencode }} {# hello+world #}Adds numbers (or concatenates strings).
{{ 4|add:2 }} {# 6 #}
{{ "hello"|add:" world" }} {# hello world #}Returns true if the value is divisible by the argument.
{% if 21|divisibleby:3 %}Yes{% endif %} {# Yes #}Formats a floating-point number.
{{ 34.23234|floatformat:2 }} {# 34.23 #}
{{ 34.00|floatformat:"-2" }} {# 34 (trims zeros) #}
{{ 34.26|floatformat }} {# 34.3 (default: -1) #}Returns the digit at the specified position (from right, 1-indexed).
{{ 123456|get_digit:2 }} {# 5 #}Converts value to float.
{{ "3.14"|float }} {# 3.140000 #}Converts value to integer.
{{ "42"|integer }} {# 42 #}
{{ 3.7|integer }} {# 3 #}Formats the value using Go's fmt.Sprintf.
{{ 3.14159|stringformat:"%.2f" }} {# 3.14 #}
{{ 42|stringformat:"%05d" }} {# 00042 #}
{{ 255|stringformat:"%x" }} {# ff #}Returns the first element.
{{ items|first }}
{{ "hello"|first }} {# h #}Returns the last element.
{{ items|last }}
{{ "hello"|last }} {# o #}Returns the length.
{{ items|length }}
{{ "hello"|length }} {# 5 #}Returns true if the length equals the argument.
{% if items|length_is:3 %}Exactly 3 items{% endif %}Joins list elements with a string.
{{ items|join:", " }} {# apple, banana, cherry #}Returns a slice of the list.
{{ items|slice:":2" }} {# First two items #}
{{ items|slice:"1:" }} {# All but first #}
{{ items|slice:"1:3" }} {# Items 1 and 2 #}
{{ items|slice:"-2:" }} {# Last two items #}Returns a random element.
{{ items|random }}Formats a date using Go's time format.
{{ now|date:"2006-01-02" }} {# 2024-01-15 #}
{{ now|date:"Monday, January 2" }} {# Monday, January 15 #}
{{ now|date:"Jan 2, 2006 3:04 PM" }} {# Jan 15, 2024 2:30 PM #}Go time format reference:
2006- Year01- Month (01-12)02- Day (01-31)15- Hour (00-23)03- Hour (01-12)04- Minute (00-59)05- Second (00-59)PM- AM/PMMonday- Day nameJanuary- Month name
Alias for date. Formats time values.
{{ now|time:"15:04:05" }} {# 14:30:45 #}Returns the argument if value is empty/false.
{{ value|default:"nothing" }}
{{ ""|default:"empty" }} {# empty #}
{{ 0|default:"zero" }} {# zero #}
{{ false|default:"nope" }} {# nope #}Returns the argument only if value is nil.
{{ value|default_if_none:"nothing" }}
{{ 0|default_if_none:"zero" }} {# 0 (not replaced) #}Maps true/false/nil to custom strings.
{{ true|yesno:"yeah,nope,maybe" }} {# yeah #}
{{ false|yesno:"yeah,nope,maybe" }} {# nope #}
{{ nil|yesno:"yeah,nope,maybe" }} {# maybe #}
{{ value|yesno }} {# yes/no/maybe (defaults) #}Returns plural suffix based on value.
{{ count }} item{{ count|pluralize }} {# items if count != 1 #}
{{ count }} cherr{{ count|pluralize:"y,ies" }} {# cherry/cherries #}
{{ count }} lun{{ count|pluralize:"ch,ches" }} {# lunch/lunches #}The following filters are available via pongo2-addons:
- filesizeformat - Formats file sizes (e.g., "13 KB")
- slugify - Converts to URL-friendly slug
- timesince - Time since a date
- timeuntil - Time until a date
- naturaltime - Human-readable time difference
- naturalday - "yesterday", "today", "tomorrow"
- intcomma - Adds commas to numbers
- ordinal - Adds ordinal suffix (1st, 2nd, 3rd)
- markdown - Renders Markdown to HTML
- truncatesentences - Truncates to N sentences
- truncatesentences_html - Same, but preserves HTML