So I have a nested dictionary in the form of the following:
data = { server:{'rating':{'class':'good, 'desc':'whatever'}, 'vulnerabilities':{'heartbleed':{'severity':'critical', 'desc':'terrible config'}}
I want to iterate through the values using keys, I've read the documentations and this is what I do in template:
{% for key, value in data.items %}
<p> 'This is the key {{ key }} and this is the value {{value}}'<p>
{% endfor %}
so far so good, the bizarre thing is that I can`t get the values using the key retrieved by the for loop, namely, when I have such a template:
{% for key in data.keys %}]
<p> 'This is the key: {{key}}' </p>
<p> 'This is the value: {{ data.key }}'<p>
{% endfor %}
{{key}}
returns the keys with no problem. Even when I do {{data.server}}
I get the corresponding values with no problem. Strange thing is that this line {{data.key}}
does not work as I intuit it to.
In one loop the key==server
, {{data.server}}
works but {{data.key}}
does not. What am I getting wrong here?