arcee123 arcee123 - 5 months ago 39
HTML Question

how to stack images from bottom up in Django

I'm starting with this code:

{% for award in data.profile.awards %}
<img src="media/{{ award.Medals.ribbon }}">
{% if forloop.counter|divisibleby:3 %}
<br />
{% endif %}
{% endfor %}

my problem is that it goes from top down. Meaning that it produces the first three, then a break, then another three, and repeat from there.

What I need is to go from bottom up. in my case, If there's 4 images, I want 1 on top, and 3 on bottom. If there's 8, then there's 2 on top, 3 in the middle, then 3 on bottom. How do I do that?



You could possibly try to invert your loop and count from end, like this:

{% if forloop.revcounter|divisibleby:3 %}
{% endif %}

So, if for example you have 10 images, 1 images will be displayed, then condition will insert break, and break will be occurred after each 3 images. Hope it helps!