Advertisement



< Prev
Next >



Django Template - Filters



In this tutorial, we are going to discuss some of the most important built-in filters provided by Django Template System. Using filers, we could modify the value of a template variable before it is displayed in the output.




Important Filters in Django Template System


Let us see some of the most important built-in filters and their brief description in Django Template System.

Filters Description
firstof
The firstof filter checks one or multiple variables passed to it as arguments and returns the first argument variable that evaluates to True.

Note: It returns nothing if all the passed variables return False.

first
The first filter returns the first item in the list.

last
The last filter returns the last item in the list

length
The length filter returns the total length of a value, which could be a string or a list.

length_is
The length_is filter returns boolean True if the value's length is the same as the value passed as the argument to filter.

linebreaks

The linebreaks filter replaces line breaks(\n)in a plain text document with HTML line break tag i.e. <br/>. It also replaces a single newline followed by a blank line with a paragraph tag i.e. <p>.

make_list
The make_list filter converts the value passed as an argument to it and returns it as a list.

lower
The lower filter converts all the characters in a string to lowercase.

upper
The upper filter converts all the characters in a string to uppercase.

title
The title filter converts all the characters in a string to titlecase.

wordcount
The wordcount filter returns the total number of words in a value.

floatformat
The floatformat filter is used to round-off a floating-point value.

filesizeformat
The filesizeformat filter is used to formats a value like a human-readable file size.

get_digit
The get_digit filter return a digit at a specific index of a value, this index is passed as an argument to the filter.

For example - the index 1 returns the right-most digit in a value, index 2 returns the second right-most digit in a value and so on.

join
The join filter is used to join a list with a string i.e. a string which is passed as an argument to this filter.



Note: To use use a filter with a value, we must be a pipe | sign.




Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement