1π
β
This is a quick example on how you can do this (this is for 2 column based itteration) but you can change it to your liking (replace β2β with a integer for instance):
<div class="row">
{% for image in image_list %}
<div class="col-sm-6">
<a href="{{ image.url }}">{{ image.name }}</a>
</div>
{% if not forloop.last and forloop.counter|divisibleby:"2" %}
</div>
<div class="row">
{% endfor %}
</div>
π€petkostas
0π
In Django Templates you can not use += 1 operator
you can use the forloop.counter
{% if forloop.counter0|divisibleby:4 %} so every 4 iterations
starting with first iteration where
counter is 0
<div class="row">
{% endif %}
<div class="col-sm-{{ taille }}">
<a href="{{ image.url }}">{{ image.name }}</a>
</div>
{% if forloop.counter0|add:"-1"|divisibleby:"4" %} also every 4 iterations
but starting with the 2nd
iteration where counter is 1
</div>
{% endif %}
π€gaw
- [Answer]-Python β how to correctly use htmlparser on alexa.com
- [Answer]-Django-1.5 DecimalField
- [Answer]-Many foreign keys in one lookup table. Bad idea?
Source:stackexchange.com