On Jan 5, 5:39 pm, "django_fo...@codechimp.net" <codech...@gmail.com>
wrote:
> I have a pretty simple template that needs to print some data in a
> bunch of table rows.  I have done something like this:
>
> <table>
> {% if my_art_list %}
>         {% count = 0 %}
>         {% for art in my_art_list %}
>                 {% if count%3 = 0 %}
>                 <tr>
>                 {% endif %}
>                         <td>
>                                 <img src="{{ art.img_path }}" alt="{{ 
> art.title }}" />
>                         </td>
>                 {% if count%3 = 2 %}
>                 </tr>
>                 {% endif %}
>         {% endfor %}
>         </tr>
> {% else %}
>         <p>You have no art pieces to view.  Would you like to add some?</p>
> {% endif %}
> </table>
>
> However, as you probably suspect, the "count" variables cause all
> sorts of trouble.  Is there a way to have tracking variables in the
> template code?  I was under the impression that the {%  %} tags were
> just straight Python code and would execute as such, but apparently my
> understanding is a little less than adequate.
>
> Please help me sort this out...

It always helps to actually read the documentation. Especially the bit
which says "the Django template system is not simply Python embedded
into HTML", in the third paragraph of the introduction to templates
here:
http://docs.djangoproject.com/en/dev/topics/templates/

What you probably need is the forloop.counter variables, detailed
here:
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#ttag-for

--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to