Hi I have very basic question. I have view like below:
def view1:
dict = ('one':'itemone','two':'itemtwo','three','itemthree')
return render_to_response('test.html',dict)
test.html
<body>
{% for key,value in dict.items %}{{ value }}{% endfor %}
</body>
it doesn't work. Can anyone suggest the correct method to iterate dictionary values in a template. Thanks in advance. Once again am sorry for my basic question.
I think you want
def view1:
d = {'one':'itemone', 'two':'itemtwo', 'three':'itemthree'}
return render_to_response('test.html', {'d':d})
and
<body>
{% for key,value in d.items %}{{ value }}{% endfor %}
</body>
Your dictionary syntax is off. Try this:
my_dict = {'one':'itemone','two':'itemtwo','three':'itemthree'}
(I'd call it something other than dict
so you're not overriding python's dict
type.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With