How to add, multiply number variables in a Django template?

前端 未结 5 1938
死守一世寂寞
死守一世寂寞 2020-12-28 19:36

The JS snippet I created relies on the forloop.counter variable being available within a {% for key, value in data.items %}..{% endfor %} tag.

Is there

5条回答
  •  天涯浪人
    2020-12-28 19:50

    It's possible to use django built-in widthratio template tag and add filter:

    • add 5 to forloop.counter {{forloop.counter|add:5}}
    • subtract 5 from forloop.counter {{forloop.counter|add:"-5"}}
    • devide forloop.counter by 5 {% widthratio forloop.counter 5 1 %}
    • multiply forloop.counter by 5 {% widthratio forloop.counter 1 5 %}

提交回复
热议问题