Re: Stupid template question
On Dec 14, 1:03 am, Steve Freitas <[EMAIL PROTECTED]> wrote: > Only, it doesn't work. It seems like . lookups > require the argument to be a literal, not a variable. Grindizer addresses your specific problem of enumerating key/value pairs in a template (piece of cake!), but if you still wanted to reference attributes with a "dynamic" name, here's an old thread where I asked the same thing, and got some good suggestions. (You can do it with a custom tag OR a custom filter) http://groups.google.com/group/django-users/browse_thread/thread/2f7c88a386ac5d59/0a53f94e28937dbe?hl=en&lnk=gst --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Stupid template question
have you take a look at the django documentation ? http://www.djangoproject.com/documentation/templates/#for Because we can see this :) {% for key, value in data.items %} {{ key }}: {{ value }} {% endfor %} On 14 déc, 08:03, Steve Freitas <[EMAIL PROTECTED]> wrote: > I have a dictionary, and I'd like to iterate over the keys, using the > keys to look up the result, like: > > {% for key in myDict %} > The key is {{key}} and the value is {{myDict.key}}. > {% endfor %} > > Only, it doesn't work. It seems like . lookups > require the argument to be a literal, not a variable. I'm sure there's > some easy way to do this, but I'm missing it. Any help would be > appreciated. > > Thanks! > > Steve --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Stupid template question
It seems that you've made a typo. change {{myDict.key}} to {{myDict.keys}} On Dec 14, 2007 3:03 PM, Steve Freitas <[EMAIL PROTECTED]> wrote: > > I have a dictionary, and I'd like to iterate over the keys, using the > keys to look up the result, like: > > {% for key in myDict %} > The key is {{key}} and the value is {{myDict.key}}. > {% endfor %} > > Only, it doesn't work. It seems like . lookups > require the argument to be a literal, not a variable. I'm sure there's > some easy way to do this, but I'm missing it. Any help would be > appreciated. > > Thanks! > > Steve > > > > > -- http://www.etng.net/blog --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Stupid template question
I have a dictionary, and I'd like to iterate over the keys, using the keys to look up the result, like: {% for key in myDict %} The key is {{key}} and the value is {{myDict.key}}. {% endfor %} Only, it doesn't work. It seems like . lookups require the argument to be a literal, not a variable. I'm sure there's some easy way to do this, but I'm missing it. Any help would be appreciated. Thanks! Steve --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---