On Friday 05 February 2010 01:02:54 harryos wrote:
> hi
> I have a dictionary object passed to the template , from which I need
> to retrieve values
>
> mydata={}
> mydict['chemistry']=120
> mydict['physics']=164
> mydict['maths']=110
>
> In my render_to_response I passed this object like
> return render_to_response("myapp/mydatapage.html",
> {'mydata_dict':mydata})
>
> I need to show this data on the page as
>
> chemistry=120
> physics=164
> math=110
>
>
> On the template html, I tried this
>
> {% for key in mydata_dict %}
> {{key}} ={{ mydata_dict[key] }}
>
> {% endfor %}
>
>
> This gives TemplateSyntaxError :Could not parse the remainder: '[key]'
> from 'mydata_dict[key]'
>
> I understand template doesn't allow [] operator..Can somebody tell me
> how I can get the value corresponding to the key?
>
> thanks
> harry
> How else
>
http://docs.djangoproject.com/en/dev/topics/templates/#variables
{{ mydata_dict.key }}
Templates use the dot operator to access attributes to a variable.
Mike
--
Understanding is always the understanding of a smaller problem
in relation to a bigger problem.
-- P.D. Ouspensky
signature.asc
Description: This is a digitally signed message part.

