Devinwon / article

0 stars 0 forks source link

divisibleby/custom tag in django template #35

Open Devinwon opened 5 years ago

Devinwon commented 5 years ago

{% if forloop.counter0|divisibleby:2 %} <# dispaly one , 0,2,4,6 .... #> {% else%} <# dispaly another 1,3,5,7,#> {% endif %}

We also can custom filter,like this : new a file named templatehelper.py code below>> @register.filter def div(value, div): ''' :param value: :param div: :return: ''' return round((value / div), 2) load in your template head>> {% load templatehelper %}

{{ amount |div:100 }}

if amount is 25, the result will be 0.25