Re: accessing dictionary values in a template for loop

2008-04-28 Thread RaviKondamuru

Figured out. {{ values|length }} gives the length of the list to be
used for rowspan tag.
thanks,
Ravi.

On Apr 28, 1:16 pm, RaviKondamuru <[EMAIL PROTECTED]> wrote:
> Thanks. With results.items, both solutions work on the svn current
> version.
>
> The variable value is a list. I would like each key,value to be in a
> separate row.
>
> {% for key, values in results.items %}
>  {% for value in values %}
>   
> {{ key }}
> {{ value }}
>   
>  {% endfor %}
> {% endfor %}
>
> This causes the same key to showup on all the rows associated with it.
> Is there a way to use html's colspan to have the key cell span all
> rows associated with it?
>
> thanks,
> Ravi.
>
> On Apr 27, 4:26 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
> wrote:
>
> > On Sun, 2008-04-27 at 13:35 -0500, Alex Ezell wrote:
>
> > [...]
>
> > > Depending on the version of Django you are using, you should be able to 
> > > do this:
>
> > > {% for key, value in results %}
> > >   
> > > {{ key }}
> > > {{ value }}
> > >   
> > > {% endfor %}
>
> > Or, for older versions:
>
> > {% for item in results.items %}
> >   
> > {{ item.0 }} {# key #}
> > {{ item.1 }} {# value #}
> >   
> > {% endfor %}
>
> > (by the way, the original example should have used results.items, too.)
>
> > Regards,
> > Malcolm
>
> > --
> > How many of you believe in telekinesis? Raise my 
> > hand...http://www.pointy-stick.com/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
-~--~~~~--~~--~--~---



Re: accessing dictionary values in a template for loop

2008-04-28 Thread RaviKondamuru

Thanks. With results.items, both solutions work on the svn current
version.

The variable value is a list. I would like each key,value to be in a
separate row.

{% for key, values in results.items %}
 {% for value in values %}
  
{{ key }}
{{ value }}
  
 {% endfor %}
{% endfor %}

This causes the same key to showup on all the rows associated with it.
Is there a way to use html's colspan to have the key cell span all
rows associated with it?

thanks,
Ravi.

On Apr 27, 4:26 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Sun, 2008-04-27 at 13:35 -0500, Alex Ezell wrote:
>
> [...]
>
> > Depending on the version of Django you are using, you should be able to do 
> > this:
>
> > {% for key, value in results %}
> >   
> > {{ key }}
> > {{ value }}
> >   
> > {% endfor %}
>
> Or, for older versions:
>
> {% for item in results.items %}
>   
> {{ item.0 }} {# key #}
> {{ item.1 }} {# value #}
>   
> {% endfor %}
>
> (by the way, the original example should have used results.items, too.)
>
> Regards,
> Malcolm
>
> --
> How many of you believe in telekinesis? Raise my 
> hand...http://www.pointy-stick.com/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
-~--~~~~--~~--~--~---



Re: accessing dictionary values in a template for loop

2008-04-27 Thread Malcolm Tredinnick


On Sun, 2008-04-27 at 13:35 -0500, Alex Ezell wrote:
[...]
> Depending on the version of Django you are using, you should be able to do 
> this:
> 
> {% for key, value in results %}
>   
> {{ key }}
> {{ value }}
>   
> {% endfor %}

Or, for older versions:

{% for item in results.items %}
  
{{ item.0 }} {# key #}
{{ item.1 }} {# value #}
  
{% endfor %}

(by the way, the original example should have used results.items, too.)

Regards,
Malcolm

-- 
How many of you believe in telekinesis? Raise my hand... 
http://www.pointy-stick.com/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
-~--~~~~--~~--~--~---



Re: accessing dictionary values in a template for loop

2008-04-27 Thread Alex Ezell

On Sun, Apr 27, 2008 at 1:27 PM, RaviKondamuru <[EMAIL PROTECTED]> wrote:
>
>  Hi,
>  I have the following lines of code to access the key, values in a
>  template for loop.
>
>  
>   
>   {% for key in results %}
> 
> {{ key|escape }}
> {{ results.key }}
> 
>   {% endfor %}
>   
>   
>
>  results.key is being treated as results['key'] and hence always
>  returning NULL. Is there a way to make it treat it as results[key], so
>  it can use value of key to find the key,value in dictionary.

Depending on the version of Django you are using, you should be able to do this:

{% for key, value in results %}
  
{{ key }}
{{ value }}
  
{% endfor %}

but I can tell by the fact that you are using "escape" that you are
most likely on an older version.

Updating to the latest SVN, if possible for you, would really help you
out and make this very easy.

/alex

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



accessing dictionary values in a template for loop

2008-04-27 Thread RaviKondamuru

Hi,
I have the following lines of code to access the key, values in a
template for loop.

 
  
  {% for key in results %}

{{ key|escape }}
{{ results.key }}

  {% endfor %}
  
  

results.key is being treated as results['key'] and hence always
returning NULL. Is there a way to make it treat it as results[key], so
it can use value of key to find the key,value in dictionary.

thanks,
Ravi.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---