python - Loop through dictionary with django -


in django, have dictionary, contains dictionary, example:

d['dict1'] = [('1', 'some information'), ('2', 'some information')] d['dict2'] = [('1', 'some more information'), ('2', 'some more information')] 

and need loop through it, each time loops through grab value of dict1 , dict2 corresponding loop.counter, example

first time through output 1 3 , 2 4 , on , forth  

i tried doing:

{% item1, item2 in d.items %} {{ item1.forloop.counter.value1 }} {{ item2.forloop.counter.value1 }} {% endfor %} 

and produces nothing.

edit: updated dict looks like

you should turn this:

d['dict1'] = [('value1', '1'), ('value2', '2')] d['dict2'] = [('value1', '3'), ('value2', '4')] 

into this:

result = [('value1', '1', '3'), ('value2', '2', '4')] 

you can in view. preparing data displayed in template.

you can iterate on values easily:

{% name, v1, v2 in result %} {{ v1 }} {{ v2 }} {% endfor %} 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -