django 模板的乘法,除法

django 模板的乘法,除法

1人收藏此文章, 收藏此文章发表于11个月前 , 已有141次阅读 共0个评论 1人收藏此文章

Note: The results are rounded to an integer before returning, so this may have marginal utility for many cases.

So, in summary:

to compute A*B: {% widthratio A 1 B %} 
to compute A/B: {% widthratio AB 1 %}

And, since add is a filter and not a tag, you can always to crazy stuff like:

compute A^2: {% widthratio A 1 A %} 
compute (A+B)^2: {% widthratio A|add:B 1 A|add:B %} 
compute (A+B) * (C+D): {% widthratio A|add:B 1 C|add:D %}

原文出处:http://slacy.com/blog/2010/07/using-djangos-widthratio-template-tag-for-multiplication-division/

原文地址:https://www.cnblogs.com/SophiaTang/p/2308177.html