Iterating dictionary indexes in django templates

Posted by unclaimedbaggage on Stack Overflow See other posts from Stack Overflow or by unclaimedbaggage
Published on 2010-06-09T02:20:38Z Indexed on 2010/06/09 2:22 UTC
Read the original article Hit count: 251

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about python

Related posts about django