5

In a django template, if I have a key within the context dictionary assocoated with another dictionary (a nested dictionary), I know how to itterate over it (how to iterate through dictionary in a dictionary in django template?) but I need to find a value by key.

like {{ nested_dictionary['key'] }}

But I'm guessing not exactly that...

Filters could be used, but is there a better way?

Community
  • 1
  • 1
jayjay
  • 1,017
  • 1
  • 11
  • 23

1 Answers1

1

Yes, if you have a nested dictionary in your view i.e.:

...
dashTable = {'Key0':{'Key1':{'Key2':{'Key3':5}}}}

context = {'dashTable':dashTable,}
return render(request, 'template.html', context)

Then you would be able to call your nested dictionary when passed through as context with:

{{ dashTable.Key0.Key1.Key2.Key3 }} 
Josh
  • 2,122
  • 1
  • 21
  • 28