Think you're not undesrtanding...

Example:

python code:
myList = ["one", "two", "three"]
for item in myList: print item

output:
one
two
three

django template tag "for" can get the itens in list in same way... but
you get the itens and the instance variables of the model model:

class ImageModel:
name
description
links

{% for image in imageList %}
{{ image.name }}
{{ image.description }}
{{ image.links }}
{% endfor %}

In your case "i" cannot be an index of your list, but is the current
item of the list itself, a instance of your Model.


2011/11/25 marjenni <[email protected]>:
> Thank you for the quick reply :)
>
> What I am currently doing is passing 3 separate lists to the template,
> each representing the column of a table so that i can do something
> this:
>
>  {% for i in numberOfImages %}
>    <tr>
>        <td> {{ images.i}} </td>
>        <td> {{ descriptions.i}} </td>
>        <td> {{ links.i}} </td>
>
> What is the best way to do this then?
>
> many thanks
>
> Mark
>
>
> On Nov 25, 1:25 pm, Tom Evans <[email protected]> wrote:
>> On Fri, Nov 25, 2011 at 1:18 PM, marjenni <[email protected]> 
>> wrote:
>> > Hi all,
>> >  Why does this not work?
>>
>> >    {% for i in numberOfImages %}
>> >          <tr>
>> >         <td> {{ images.i}} </td>
>>
>> It doesn't work because there is no variable interpolation inside a
>> template tag. That snippet asks for the attribute named 'i' on the
>> 'images' variable.
>>
>> As an earlier poster said, pass a list of images to output, and then
>> iterate through that list. If you need the ordinal of where you are in
>> the list, that is made available by the for tag:
>>
>> https://docs.djangoproject.com/en/1.3/ref/templates/builtins/#for
>>
>> Cheers
>>
>> Tom
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to