Is there a filter for divide for Django Template?

前端 未结 6 1877
囚心锁ツ
囚心锁ツ 2020-12-20 11:01

I noticed there is built-in add filter, but I wasn\'t able to find divide.

I am new to Django and not sure if there is a such filter.

6条回答
  •  庸人自扰
    2020-12-20 11:43

    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/

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

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

    to compute A^2: {% widthratio A 1 A %}

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

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

    Also you can create a filter to division in 2 minutes

提交回复
热议问题