How can I know when the third multiple is reached in an arbitrarily long list

7 views
Skip to first unread message

Jason

unread,
Feb 13, 2012, 5:25:39 PM2/13/12
to django...@googlegroups.com
Hi there,

I'm trying to put together a photo album using django client side and I want to align the photo's 3 in a row. In order to do this I'm putting the photo's in a table (not ideal I know...) and I was wondering how I can have a table row with 3 images only? Right now my table just puts a bunch of photos in a row but I cannot figure out how to start a new row after 3 images have been put in. 

Any ideas would be appreciated.


What I've got so far is:

<h1>{{the_adventures.adventure_name}} <small>{{the_adventures.adventure_date}}<small></h1>
    <table>
        <tr>
        {% for photo in the_adventures.the_photos %}
            <td>
                <img  height="100px" width="100px" src ="/serve/{{ photo.blob_key.key }}">
            </td>
        {% endfor %}
        </tr>
    </table>
<a href = "/view_album/{{the_adventures.adventure_name}}/{{the_adventures.adventure_date}}/{{the_adventures.cursor}}">Next page</a>


What I want is:

image image image
image image image
image image image

etc

Shawn Milochik

unread,
Feb 13, 2012, 5:28:06 PM2/13/12
to django...@googlegroups.com
You can use the divisibleby template tag in combination with a
forloop.counter (both explained on this page):

https://docs.djangoproject.com/en/1.3/ref/templates/builtins/#divisibleby

Jason

unread,
Feb 13, 2012, 5:58:24 PM2/13/12
to django...@googlegroups.com
Thank you so much Shawn - you saved the day there!
Reply all
Reply to author
Forward
0 new messages