Django模板是否有分隔的过滤器? [英] Is there a filter for divide for Django Template?
问题描述
我注意到内置添加
过滤器,但是我找不到分割
。
I noticed there is built-in add
filter, but I wasn't able to find divide
.
我是Django的新手,不知道是否有这样的过滤器。
I am new to Django and not sure if there is a such filter.
推荐答案
没有。但是如果你是一个小黑客....
There is not it. But if you are a little hacker....
http://slacy.com/blog/2010/07/using-djangos-widthratio-template-tag-for-multiplication-division/
计算A * B:{%widthratio A 1 B%}
to compute A*B: {% widthratio A 1 B %}
计算A / B:{%widthratio AB 1%}
to compute A/B: {% widthratio A B 1 %}
计算A ^ 2:{%widthratio A 1 A%}
to compute A^2: {% widthratio A 1 A %}
计算(A + B)^ 2:{%widthratio A | add:B 1 A | add:B%}
to compute (A+B)^2: {% widthratio A|add:B 1 A|add:B %}
计算(A + B)*(C + D):{%widthratio A | add:B 1 C | add:D%}
to compute (A+B) * (C+D): {% widthratio A|add:B 1 C|add:D %}
此外,您可以在2分钟内创建一个过滤器来分割
Also you can create a filter to division in 2 minutes
这篇关于Django模板是否有分隔的过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!