Multiply in django template

后端 未结 4 1735
无人及你
无人及你 2020-12-10 14:30

I am looping through cart-items, and want to multiply quantity with unit-price like this:

{% for cart_item in cart.cartitem_set.all %}
{{cart_item.quantity}}         


        
4条回答
  •  鱼传尺愫
    2020-12-10 15:02

    You can use widthratio builtin filter for multiplication and division.

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

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

    source: link

    Notice: For irrational numbers, the result will round to integer.

提交回复
热议问题