我希望将表(teams)中的所有数据库条目打印到.html文件中,然后应用自定义格式。
对于数据库,我有一个名为Teams的数据库表,它包含用于TEAM_NAME和COUNTRY的列
在我的烧瓶应用程序中,我有以下的应用程序路径和功能:
# views.py
@app.route('/test')
def test_route():
conn = sqlite3.connect("test.db")
c = conn.cursor()
c.execute("select * from Teams") # get db entries
teams = [] # init list
i = 0
while True:
res = c.fetchone() # get row
if res is None:
break
else:
teams.append(res) # add row to teams list
i += 1
return render_template('test.html', teams=teams)那么我就有了test.html文件。在这里,我希望能够在单独的段落中打印所有的数据库条目。为此,我可以这样对它们进行硬编码:
<body>
<p>{{teams[0]}}</p>
<p>{{teams[1]}}</p>
<p>{{teams[2]}}</p>
<p>{{teams[3]}}</p>
<p>{{teams[4]}}</p>
<p>{{teams[5]}}</p>
</body>如何打印所有оut必须硬编码他们的id的团队?
发布于 2018-07-04 17:10:02
<body>
{% for team in teams %}
<p>{{team}}</p>
{% endfor %}
</body>检查jinja文档模板可以做什么
https://stackoverflow.com/questions/51178322
复制相似问题