On Aug 19, 8:55 am, elminio <wgruszczyn...@gmail.com> wrote:
> You don't understand me.
> WQhat I want to achieve is to use student.id as a key in dictionary
> (Im talking abous template)
> If I use:
>
> {% for student in students %}
>
> ... do sth ...
>
> <p> {{dictionary.student.id }} </p>
>
> {% endfor %}
>
> using dictionary.1 works using dictionary.student.id doesnt work
> because there is no such key like student in dictionary. What can I do
> to convert student.id to value and pass it like for example dictionary.
> (student.id)
>
> if in this iteration student.id = 5 then i want to have {{ dictionary.
> 5 }}
>
> thats all

As has been explained, you can't do this straight out of the box.
However it is trivially easy to write a custom template filter that
will do it.

@register.filter
def get(dictionary, key):
    return dictionary.get(key)

Now you can do {{ dictionary.get:5 }}

--
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