Answer the question
In order to leave comments, you need to log in
How to output defaultdict element by element in Django template?
We have the following code:
from collections import defaultdict
foo = defaultdict(dict)
foo[1][1] = 12
foo[1][2] = 24
foo[2][1] = 36
foo[2][2] = 48
foo[3]['string'] = 'foo bar'
print foo[2][1]
print foo[3]['string']
Answer the question
In order to leave comments, you need to log in
Create a custom filter that gets an element from a dict.
@register.filter
def get_item(v, a):
return v.get(a)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question