0

I want to display data in the table using flask forloop.
I have the Following Array called "mainarray"

[
    ('x', 'y', 'z'),
    ('a', 'b', 'c'),
    ('m', 'n', 'o')
]

Currently, I am using following method

{% for newmainarray in mainarray %}
    <td>{{ newmainarray [0] }}</td>
    <td>{{ newmainarray [1] }}</td>
    <td>{{ newmainarray [2] }}</td>
{% endfor %}

Currently, it's working for me, but I have seen in some tutorials that we can display data by using {{newmainarray.keyname}}.

However, it's not working for me. I will be very thankful if anyone can help me with this.

4

1 回答 1

0

您不能使用{{newmainarray.keyname}},因为mainarray包含数组/元组而不是字典。为了使用.keyname模式,您需要设置mainarray如下:

[
     {'key':'x', 'other_key':'y'},
]

或者,您可以使用newmainarray数组索引访问newmainarray.index_number

于 2020-08-01T12:19:37.073 回答