Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fetching list elements using jinja2 under flask app

I have a list say list[a][b] of length 10. I want to print from list[0][b] to list[10][b] and use it in jinja2 template.

{% for i in test %}
<p> {{test[i][0]}} </p>
{% endfor %}

throws error:

UndefinedError: list object has no element 
like image 816
Chandan Gupta Avatar asked Dec 11 '22 13:12

Chandan Gupta


1 Answers

You actually get the element out of the list when you iterate over it, not the index value:

{% for row in test %}
    {# Note that we subscript `row` directly,
    (rather than attempting to index `test` with `row`) #}
    <p>{{ row[0] }}</p>
{% endfor %}
like image 76
Sean Vieira Avatar answered Jan 01 '23 05:01

Sean Vieira