I have this code
{% for o in some_list %}
Now I want to do some stuff if I am on an even line. How can I do that?
To order them in the view I would need to iterate through the events and for each event create a container of some sort of the attendees related to that event in properly sorted order, then pass that entire collection of containers to the template in a form that would let the template find the appropriate collection of ...
{% %} and {{ }} are part of Django templating language. They are used to pass the variables from views to template. {% %} is basically used when you have an expression and are called tags while {{ }} is used to simply access the variable.
Django for loop counter All the variables related to the counter are listed below. forloop. counter: By using this, the iteration of the loop starts from index 1. forloop. counter0: By using this, the iteration of the loop starts from index 0.
https://docs.djangoproject.com/en/dev/ref/templates/builtins/#divisibleby
{% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}
In first level cycle:
{% cycle 'odd' 'even' %}
cycle
template tagIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With