Jinja2/python中的For循环不工作(使用sqlite3)

Jinja2/python中的For循环不工作(使用sqlite3),python,sqlite,flask,jinja2,Python,Sqlite,Flask,Jinja2,我在jinja有以下for循环: <table> <thead> <td>Stock</td> <td>Shares</td> <td>Total</td> </thead> <tbody> {% for dict in rows2 %} <tr> {% f

我在jinja有以下for循环:

<table>
   <thead>
       <td>Stock</td>
       <td>Shares</td>
       <td>Total</td>
   </thead>
   <tbody>
       {% for dict in rows2 %}
       <tr>
           {% for key, value in dict.items() %}
           <td> {{value}} </td>
           {% endfor %}
       </tr>
       {% endfor %}
   </tbody>
</table>
现在,如果我将行2打印到控制台,我实际上得到了我想要的,这是这样的:

[{'stock': 'AAPL', 'amount': 1, 'total_value': 676.4}, {'stock': 'BB', 'amount': 1, 'total_value': 10.53}, {'stock': 'IBM', 'amount': 1, 'total_value': 144.99}]
但网页中的表格仅显示标题部分,实际数据部分留空!为什么会这样


干杯

省略以下项目:

{% for key, value in dict.items %}
....
{% endif %}

根据您的评论,我认为罪魁祸首是您调用render_模板。您不仅需要传递模板名称,还需要传递模板中使用的变量

所以你真的应该这么做

return render_template("portfolio.html", rows2=rows2)

。。。其中左侧是模板中的名称,右侧是在逻辑中分配给的变量。

是否将行2正确传递给渲染调用?我想是这样的?返回render_templateportfolio.html,其中portfolio是表所在的文件。将代码发布为如何呈现模板?尝试了此操作,但不幸的是它似乎仍然没有显示任何数据:/@JustABeginner,根据您关于呈现的评论,我完全更改了答案。这有用吗?耶!!!它起作用了!:D谢谢你!!!我不知道我必须传递参数,这似乎有点多余,因为变量rows2已经在应用程序覆盖主页路径的部分中了!
return render_template("portfolio.html", rows2=rows2)