Django Tutorial · Django References

Filter Reference

Learn all about Filter Reference in this comprehensive tutorial.

5 min read intermediate
  • A list of all filter keywords:

Filter Reference

A list of all filter keywords:

KeywordDescription
addAdds a specified value.
addslashesAdds a slash before any quote characters, to escape strings.
capfirstReturns the first letter in uppercase.
centerCenters the value in the middle of a specified width.
cutRemoves any specified character or phrases.
dateReturns dates in the specified format.
defaultReturns a specified value if the value is False.
default_if_noneReturns a specified value if the value is None.
dictsortSorts a dictionary by the given value.
dictsortreversedSorts a dictionary reversed, by the given value.
divisiblebyReturns True if the value can be divided by the specified number, otherwise it returns False.
escapeEscapes HTML code from a string.
escapejsEscapes JavaScript code from a string.
filesizeformatReturns a number into a file size format.
firstReturns the first item of an object (for Strings, the first character is returned).
floatformatRounds floating numbers to a specified number of decimals, default one decimal.
force_escapeEscapes HTML code from a string.
get_digitReturns a specific digit of a number.
iriencodeConvert an IRI into a URL friendly string.
joinReturns the items of a list into a string.
json_scriptReturns an object into a JSON object surrounded by <script></script> tags.
lastReturns the last item of an object (for Strings, the last character is returned).
lengthReturns the number of items in an object, or the number of characters in a string.
length_isReturns True if the length is the same as the specified number
linebreaksReturns the text with <br> instead of line breaks, and <p> instead of more than one line break.
linebreaksbrReturns the text with <br> instead of line breaks.
linenumbersReturns the text with line numbers for each line.
ljustLeft aligns the value according to a specified width
lowerReturns the text in lower case letters.
make_listConverts a value into a list object.
phone2numericConverts phone numbers with letters into numeric phone numbers.
pluralizeAdds a 's' at the end of a value if the specified numeric value is not 1.
pprint
randomReturns a random item of an object
rjustRight aligns the value according to a specified width
safeMarks that this text is safe and should not be HTML escaped.
safeseqMarks each item of an object as safe and the item should not be HTML escaped.
sliceReturns a specified slice of a text or object.
slugifyConverts text into one long alphanumeric-lower-case word.
stringformatConverts the value into a specified format.
striptagsRemoves HTML tags from a text.
timeReturns a time in the specified format.
timesinceReturns the difference between two datetimes.
timeuntilReturns the difference between two datetimes.
titleUpper cases the first character of each word in a text, all other characters are converted to lower case.
truncatecharsShortens a string into the specified number of characters.
truncatechars_htmlShortens a string into the specified number of characters, not considering the length of any HTML tags.
truncatewordsShortens a string into the specified number of words.
truncatewords_htmlShortens a string into the specified number of words, not considering any HTML tags.
unordered_listReturns the items of an object as an unordered HTML list.
upperReturns the text in upper case letters.
urlencodeURL encodes a string.
urlizeReturns any URLs in a string as HTML links.
urlizetruncReturns any URLs in a string as HTML links, but shortens the links into the specified number of characters.
wordcountReturns the number of words in a text.
wordwrapWrap words at a specified number of characters.
yesnoConverts Booleans values into specified values.
i18n
l10n
tz

Module quiz

2 questions
1

Which of the following is true about Filter Reference?

2

What is the most common pitfall when working with Filter Reference?

Answer all questions to submit.