Filters
58 filters
-
add
adds
argto the value. - addslashes adds backslashes before quotation marks to escape them.
- capfirst capitalizes the first letter of a value.
-
center
centers a value within text of
ncharacters -
cut
removes all instances of
string_to_cutfrom the value. - date for formatting dates. Most useful
-
default
used to provide a default string when the variable evaluates to
False. Most useful -
default_if_none
outputs
defaultif and only if the value isNone. -
dictsort
sorts a list of dictionaries by
key. -
dictsortreversed
reverse sorts a list of dictionaries by
key. -
divisibleby
returns
Trueif the value is divisible byn. - escape escapes HTML characters.
- escapejs escapes characters used in JavaScript strings.
-
escapeseq
applies the
escapefilter to each element of a sequence. New in Django 5.0 - filesizeformat converts a value in bytes to a friendly file size format. Most useful
- first outputs the first element in a sequence.
-
floatformat
rounds a float to
ndecimal places. Most useful -
force_escape
Almost identical to
escape. -
get_digit
returns the digit
icharacters from the right side of the value. - iriencode converts an IRI to a string that can be used in a URL.
-
join
joins a list on
s. Works just like Python’ss.join(value). -
json_script
outputs a Python object as JSON inside of a
scriptelement. Most useful - last outputs the last element in a sequence.
- length returns the length of a value. Most useful
-
length_is
Deprecated. Use
lengthwith comparison instead. Removed in Django 5.1 -
linebreaks
converts newlines to
<br>and<p>tags. -
linebreaksbr
converts all newline characters in
valueto<br>tags. - linenumbers prepends each line of text with a line number.
-
ljust
left justifies a value within text of
ncharacters - lower converts a string to lowercase.
- make_list converts the value to a list of characters.
- phone2numeric converts letters to numbers for a phone number.
- pluralize returns a pluralization suffix. Most useful
- pprint Pretty prints a Python object. Used for debugging.
- random outputs a random item from a sequence.
-
rjust
right justifies a value within text of
ncharacters - safe indicates that the value is known to be safe and therefore does not need to be escaped. Most useful
-
safeseq
applies the
safefilter to each element of a sequence. - slice returns a slice of a sequence. Most useful
- slugify converts a string to a slug.
- stringformat formats a string.
- striptags strips HTML tags.
- time for formatting times. Most useful
-
timesince
outputs the amount of time between the value and
to_date. Most useful -
timeuntil
outputs the amount of time between
from_dateand the value. Most useful - title capitalizes the first letter of each word in a value.
-
truncatechars
truncates a value to
ncharacters and appends an ellipsis (…). -
truncatechars_html
truncates a value to
ncharacters and appends an ellipsis (…). Smart about HTML tags. -
truncatewords
truncates a value to
nwords and appends an ellipsis (…). -
truncatewords_html
truncates a value to
nwords and appends an ellipsis (…). Smart about HTML tags. Most useful - unordered_list creates an unordered HTML list from a Python list of lists.
- upper converts a string to uppercase.
- urlencode escapes a string for use in a URL. Most useful
-
urlize
converts URLs in a string to clickable links by wrapping them in an
<a>tag. -
urlizetrunc
like
urlize, but truncates the link text. - wordcount outputs the number of words in a value.
-
wordwrap
inserts newline after every
ncharacters. -
yesno
maps
True,False, andNoneto mapped values. Most useful
