HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
The add
filter adds a specified argument to a
value.
The add
filter tries to convert the values
into numbers and return the sum, but if is not possible to convert the values into numbers, the specified
argument will be added at the end:
Add the phrase "-CHECK" at the end of each fruit:
{% for x in fruits %}
<h1>{{ x|add:"-CHECK" }}</h1>
{% endfor %}
You can also add one list to another:
Add the list vegetables
at the end of the
list fruits
:
{{ fruits|add:vegetables }}
Note: If Django is unable to convert the values into the same data type, it will return an empty string.
{{ value|add:valuetoadd }}
Template filters are defined by using a pipe |
character followed by the name of the filter.
Arguments are defined by using a colon :
character followed by the argument value.
Value | Description |
---|---|
valuetoadd | Required. The value to add to the original value. If both values can be converted to numbers, the sum will be returned, otherwise the added value will be added at the end of the original value. |