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/