...

Open source softwares - Django

Back to Course

Lesson Description


Lession - #1058 Django-Filter


Filter a Value

With the pipe | character followed by a filter name, you can run a value through a filter prior to bringing it back.

The name of the filter characterizes how the filter will manage the value.
Example
Return the variable firstname with upper case letters:
<h1>Hello {{ firstname|upper }}, how are you?</h1>

Multiple Filters

You can add more than one filter by adding pipe | characters followed by filter names:
Example
Return the first character of variable firstname, in lower case:
<h1>Hello {{ firstname|first|lower }}, how are you?</h1>

The filter Tag

The filter tag permits you to run an entire segment of code through a filter, and return it as indicated by the filter keyword(s>
.
Example
Return the variable firstname with upper case letters:
{% filter upper %}
  <h1>Hello everyone, how are you?</h1>
{% endfilter %}

To add numerous filters, separate the keywords with the pipe | character:

Example
Separate filters with the pipe character:
{% filter upper|linenumbers %}Hello!
my name is
Emil.
What is your name?{% endfilter %}