'Using forloop.counter to iterate over list in django template
I have a list of objects named chargers_list
and on my view I estimate when will the charging be done. List of estimates is the same size and is named eta
. I iterate over chargers {% for charger in charger_list %}
to display some information about every charger. Inside that loop I want to print estimated time. Simple ETA: {{eta.0|date:'Y-m-d H:i'}}
works if I provide the index. But how can I utilize forloop.counter (that's the only way I thought of doing this)? When I simply ETA: {{eta.forloop.counter|date:'Y-m-d H:i'}}
it throws an error:
Exception Type: TemplateSyntaxError
Exception Value:
Could not parse some characters: eta|[forloop.counter]||date:'Y-m-d H:i'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|