librelist archives

« back to archive

Unwrapping dicts in the template

Unwrapping dicts in the template

From:
pronoyc@gmail.com
Date:
2012-05-18 @ 11:07
Hello,

When I unwrap the dict in IDLE I use

for i in foo_dict:
   print i['bar']

but in the templates

<table>
{% for i in foo_dict %}
<tr>
  <td>i['bar']
  <td>i['bar2']
</tr>
{% endfor %}
</table>

gives me a table that has i['bar'] and i['bar2'] written as many times as
there are objects.

Q: How do I unwrap the dict in the templates? Do I need to unwrap them in
the views function and pass them to the template?
-- 
Regards,

Pronoy Chopra
http://blog.pronoy.in <http://www.pronoy.in/about>/
http://www.twitter.com/pronoyc

Re: Unwrapping dicts in the template

From:
pronoyc@gmail.com
Date:
2012-05-18 @ 11:12
Nevermind, I just checked the documentation for flaskr

and it's supposed to be {{ i.bar }}

Sorry for the spam.

On Fri, May 18, 2012 at 4:37 PM, pronoyc@gmail.com <pronoyc@gmail.com>wrote:

> Hello,
>
> When I unwrap the dict in IDLE I use
>
> for i in foo_dict:
>    print i['bar']
>
> but in the templates
>
> <table>
> {% for i in foo_dict %}
> <tr>
>   <td>i['bar']
>   <td>i['bar2']
> </tr>
> {% endfor %}
> </table>
>
> gives me a table that has i['bar'] and i['bar2'] written as many times as
> there are objects.
>
> Q: How do I unwrap the dict in the templates? Do I need to unwrap them in
> the views function and pass them to the template?
>  --
> Regards,
>
> Pronoy Chopra
> http://blog.pronoy.in <http://www.pronoy.in/about>/
> http://www.twitter.com/pronoyc
>
>


-- 
Regards,

Pronoy Chopra
http://blog.pronoy.in <http://www.pronoy.in/about>/
http://www.twitter.com/pronoyc