thedeepfield
thedeepfield

Reputation: 6196

Django: displaying value from a list of lists

I have a list of lists

list = [[1,2,3],[4,5,6],[7,8,9]]

How do I display the second value from each list in a template: 2, 5, 8?

<div>
    <ul class="list-group">
        {% for item in list %}
            {{ item[1] }},
        {% endfor %}
    </ul>
</div>

Upvotes: 1

Views: 1702

Answers (1)

iperelivskiy
iperelivskiy

Reputation: 3591

You have to use dot notation to access list items:

<div>
    <ul class="list-group">
        {% for item in list %}
            {{ item.1 }},
        {% endfor %}
    </ul>
</div>

Upvotes: 5

Related Questions