views:

25

answers:

1

Hi,

I want to fill a table with a list of results. But not sure how to tell the template that it's time to close current and start a new one, after 3 products was already displayed in current tr....

Would be happy if somebody could advice on it. I am running django 1.1.1

+1  A: 

Easiest way is to use the divisibleby filter.

{% for item in results %}
{% if forloop.counter0|divisibleby:3 %}<tr>{% endif %}
<td>{{ item }}</td>
{% if forloop.counter|divisibleby:3 %}</tr>{% endif %}
{% endfor %}
Daniel Roseman