There is an inflexibility indeed, because the template is meant for
designers, not programmers.
Try {% for key, value in MyList.items %} instead.
A hackier solution would be to write your custom template tag like {%
get_from_dict foo bar %} to try to get foo[bar]. But in this case you can
just use items(), as it's often the case when iterating over dictionaries.
Cheers,
AT
On Thu, Sep 8, 2011 at 4:24 PM, Rami <[email protected]> wrote:
> Hi,
> I have a dict var defined in server side, like PHONE_BOOK={1:'634534',
> 2:'264886', 3:'455346' etc..}
> Then in my django template I have this loop where I need to print the
> PHONE_BOOK[loop counter]:
> {% for Item in MyList %}
>
> Item.first_name | PHONE_BOOK.forloop.counter
>
> {% endfor %}
> ---------------------------------
> For some reason PHONE_BOOK.forloop.counter doesn't work and neither
> the more direct ways like PHONE_BOOK[forloop.counter]; it seems to me
> that there's a bit of an inflexibility in the django template renderin
> mechanism.
>
> Any idea how to solve that?
>
> Thanks.
>
> --
> 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.