Friday, November 25, 2011

Re: iterating through lists in templates

<p>Number of Images: {{ imageList.count }}</p>
{% for image in imageList %}
<tr><td>Image Name</td><td>Image File</td></tr>
<tr><td>{{ image.name }}</td><td>{{ image.file }}</td></tr>
{% endfor %}

2011/11/25 Ivo Brodien <ib@brodien.de>:
> You should pass a list of images to the template and iterate over this list.
>
> On Nov 25, 2011, at 14:18, marjenni <mark.jennings.email@gmail.com> wrote:
>
>> Hi all,
>>  Why does this not work?
>>
>>    {% for i in numberOfImages %}
>>          <tr>
>>         <td> {{ images.i}} </td>
>>
>> numberOfImages is the number of items in the images list.
>>
>> I have a workaround using images.pop, but ideally i would like to be
>> able to use an array index.
>>
>> all help much appreciated
>>
>> Mark
>>
>> --
>> 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+unsubscribe@googlegroups.com.
>> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> 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+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
>

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment