155👍
✅
https://docs.djangoproject.com/en/dev/ref/templates/builtins/#divisibleby
{% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}
98👍
- [Django]-Specifying a mySQL ENUM in a Django model
- [Django]-How to stop gunicorn properly
- [Django]-How to return HTTP 400 response in Django?
8👍
<div class="row">
{% for post in posts %}
{% cycle 'odd' 'even' %}
{% if cycle == 'odd' %}
<div class="col-md-6">Odd posts</div>
{% else %}
<div class="col-md-6">Even posts</div>
{% endif %}
{% endfor %}
</div>
OR
<div class="row">
{% for post in posts %}
{% if forloop.counter|divisibleby:2 %}
<div class="col-md-6">Even posts</div>
{% else %}
<div class="col-md-6">Odd posts</div>
{% endif %}
{% endfor %}
</div>
- [Django]-Writing a __init__ function to be used in django model
- [Django]-How do I convert datetime.timedelta to minutes, hours in Python?
- [Django]-Django values_list vs values
1👍
<div class="row">
{% for post in posts %}
{% if loop.index is divisibleby 2 %}
<div class="col-md-6">Even posts</div>
{% else %}
<div class="col-md-6">Odd posts</div>
{% endif %}
{% endfor %}
</div>
http://mitsuhiko.pocoo.org/jinja2docs/html/templates.html#id3
- [Django]-Set up a scheduled job?
- [Django]-What does "'tests' module incorrectly imported" mean?
- [Django]-Gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3> django
Source:stackexchange.com