According to The Django Book, Django's templating system supports nested dot lookups:
Dot lookups can be nested multiple levels deep. For instance, the following example uses {{ person.name.upper }}, which translates into a dictionary lookup (person['name']), then a method call (upper()): '{{ person.name.upper }} is {{ person.age }} years old.'
Are there goblins with this approach not widely covered in the documentation? I am having problems with nested dot lookups -- here's a minimal example:
views.py:
test = [{'foo': [1, 2, 3], 'bar': [4, 5, 6]}, {'baz': [7, 8, 9]}]
ndx = 'bar'
t = loader.get_template('meh.html')
c = Context({'test': test,
'ndx': ndx,})
return HttpResponse(t.render(c))
meh.html template:
<pre>
{{ test }}
{{ test.0 }}
{{ test.0.ndx }}
</pre>
Resulting HTML:
<pre>
[{'foo': [1, 2, 3], 'bar': [4, 5, 6]}, {'baz': [7, 8, 9]}]
{'foo': [1, 2, 3], 'bar': [4, 5, 6]}
</pre>
The nested lookup of a dictionary key within a list element returns nothing, when I expect [4, 5, 6].
J.J.