I have a list with IP Addresses. I also have a nested dictionary which uses those addresses as keys. For example:
my_list = ['1.2.3.4', '8.8.8.8']
my_dic = {'data': {'1.2.3.4': 'My First Data', '8.8.8.8': 'My Second Data'}}
In my template I am trying to this:
for each in my_list:
print(my_dic['data'][each])
Everything works well until I hit that each
key. So if I just print my_dic
or my_dic[data]
it will all work correctly. But when I add the each
index nothing shows up in the webpage
I have printed each
independently so I know that it works correctly.
This also works as expected when I run the loop in my IDE so I know the logic is right.
In django my code looks like this:
{% if my_dic.data %}
{% for each in my_list %}
<p>{{ my_dic.data.each }}</p>
{% endfor %}
{% endif %}
I'm new to Django so not sure if I'm overlooking something silly. Anyone know what I am missing here?
EDIT Found a duplicate HERE which covers my issue. Same issue Vishnu Ks pointed out.