Question

does anybody know the answer? For instance, I have a div container and several items in it:

<div class="row">
  {% for item in filtered %}
    <img src="..."/>
    <img src="..."/>
    <img src="..."/>
  {% endfor %}
</div>

In the above code I need to have only 3 images, so for the next images in a loop it should create new DIV, like this:

<div class="row">
    <img src="..."/>
    <img src="..."/>
    <img src="..."/>
</div>
<div class="row">
    <img src="..."/>
    <img src="..."/>
    <img src="..."/>
</div>

The issue is: I have iterating images and also should have iterating div.row, because I need only 3 images per div. I was looking for an answer everywhere, but no luck. So basically I need to check multiplicity in {{ forloop.counter }} I think. Any ideas?

Était-ce utile?

La solution

The divisible by filter could be helpful or the cycle filter

https://docs.djangoproject.com/en/dev/ref/templates/builtins

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top