Python Django Template: Iterate Through List

djangodjango-templatespython

Technically it should iterate from 0 to rangeLength outputting the user name of the c[i][0].from_user…but from looking at example online, they seem to replace the brackets with dot notation. I have the following code:

<div id="right_pod">
{%for i in rangeLength%}
    <div class="user_pod" >
        {{c.i.0.from_user}}
    </div>
{% endfor %}

This currently outputs nothing 🙁 If I replace "i" with 0…{{c.0.0.from_user}}…it will output something.. (the first user 10 times)

Best Answer

Do you need i to be an index? If not, see if the following code does what you're after:

<div id="right_pod">
{% for i in c %}
    <div class="user_pod">
        {{ i.0.from_user }}
    </div>
{% endfor %}