I am having trouble with using the template language dot notation to access values in my dictionary.
Here is an example of what one of my dictionary’s could look like:
{2L: {'dob': datetime.date(2012, 7, 7), 'image': u'', 'user_id': 3L, 'id': 2L, 'email': u'blank@blank.com'}, 3L: {'dob': datetime.date(2012, 7, 7), 'image': u'', 'user_id': 4L, 'id': 3L, 'email': u'blank@blank.com'}}
The way I would access this in Python is like so:
D[2]['email']
Here is what I’ve tried in my template:
{% for d in D %}
{% if d == a.user_id %} {{ D.d.email }} {% endif %}
{% endfor %}
It is not printing out anything… (I have tested that my boolean evaluates to True, by adding some HTML inside the execution block.
Can you help me with the notation here? I know its this: {{ D.d.email }} that is wrong.
Thank you.
You don’t want
{{ D.d.email }}, that looks up D[‘d’]. There is no syntax in Django templates to use a variable as a key.Use this: