Iterating dictionary indexes in django templates
- by unclaimedbaggage
Hi folks...I have a dictionary with embedded objects, which looks something like this:
notes = {
2009: [<Note: Test note>, <Note: Another test note>],
2010: [<Note: Third test note>, <Note: Fourth test note>],
}
I'm trying to access each of the note objects inside a django template, and having a helluva time navigating to them. In short, I'm not sure how to extract by index in django templating.
Current template code is:
<h3>Notes</h3>
{% for year in notes %}
{{ year }} # Works fine
{% for note in notes.year %}
{{ note }} # Returns blank
{% endfor %}
{% endfor %}
If I replace {% for note in notes.year %} with {% for note in notes.2010 %} things work fine, but I need that '2010' to be dynamic.
Any suggestions much appreciated.