24👍
✅
The cycle tag is designed for this type of problem:
{% for field in form %}
<li class="{% cycle 'thiscolor' 'thatcolor' %}">{{ field }}</li>
{% endfor %}
21👍
I agree with Jarret that cycle
is best here, but to actually answer the question, the %2==0
operation can be replicated by using the divisibleby
filter.
{% if forloop.counter|divisibleby:"2" %}
- How to build sphinx documentation for django project
- How to give foreign key name in django
- How do you create a Django HttpRequest object with the META fields populated?
- How can you dispatch on request method in Django URLpatterns?
- Django and postgresql testing schema
1👍
Another thing to keep in mind is that since this is a front end problem – the styling is what you’re trying to effect – you can solve it on the front end. There’s a good example provided toward the bottom of this A List Apart article. Of course, if you’ve already got working Django code there’s no sense in doing this now.
- Args and kwargs in django views
- Django create superuser from batch file
- Django and service workers – serve "sw.js" at application's root url
- Django – template context processors – breaking my app
Source:stackexchange.com