Django Built-in template filter
2017-07-28 本文已影响0人
swotpp
NB:
- 在 add 的后面不能有空格
- django会先转为整数再进行计算
add
Adds the argument to the value.
For example:
{{ value|[add](#add):"2" }}
If value is 4, then the output will be 6.
This filter will first try to coerce both values to integers. If this fails, it’ll attempt to add the values together anyway. This will work on some data types (strings, list, etc.) and fail on others. If it fails, the result will be an empty string.
For example, if we have:
{{ first|[add](#add):second }}
and first is [1, 2, 3] and second is [4, 5, 6], then the output will be [1, 2, 3, 4, 5, 6].