How to print the value of a key from the key itself
dict={}
dict.update({'aa':1})
dict.update({'ab':1})
dict.update({'ac':1})
return render_to_response(t.html,  context_instance=RequestContext(request, {'dict':dict}))
So in this case i want to print the key alert('{{dict.aa}}'); i.e,without using any loop can we just print the key with the reference of aa in the the above example may some thing like if {{dict['aa']}}   should give the value of aa
Never call a dictionary dict, that would overwrite the builtin dict type name in the current scope.
You can access keys and values in the template like so:
{% for item in d.items %}
    key = {{ item.0 }}
    value = {{ item.1 }}
{% endfor %}
or use d.keys if you only need the keys.
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