我想迭代一個二維陣列來列印一個單元格中的每個元素,我怎么能在 jinja 中寫這個?
到目前為止,我的代碼僅在單個單元格中列印每一行(包含三個元素):
Data: [[90,50,30],
[40,20,70],
[60,80,10]]
<div class="container">
<table class="table">
<thead>
<th>No</th>
<th>Value of Row 1</th>
<th>Value of Row 2</th>
<th>Value of Row 3</th>
</thead>
<tbody>
{% for i in array %}
<tr>
<td>{{ loop.index }}</td>
<td>{{ i }}</td>
<td>{{ i }}</td>
<td>{{ i }}</td>
</tr>
{% endfor %}
</div>
預期輸出:
| 不 | 第 1 行的值 | 第 2 行的值 | 第 3 行的值 |
|---|---|---|---|
| 1 | 90 | 50 | 30 |
| 2 | 40 | 20 | 70 |
| 3 | 60 | 80 | 10 |
uj5u.com熱心網友回復:
將您的模板更改為:
<div class="container">
<table class="table">
<thead>
<th>No</th>
<th>Value of Row 1</th>
<th>Value of Row 2</th>
<th>Value of Row 3</th>
</thead>
<tbody>
{% for row in data %}
<tr>
<td>{{ loop.index }}</td>
{% for cell in row %}
<td>{{ cell }}</td>
{% endfor %}
</tr>
{% endfor %}
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/355657.html
標籤:Python for循环 烧瓶 多维数组 jinja2
上一篇:運行應用程式時在燒瓶中出錯
