我有一个连接的 SQL 花卉数据库(属、种、名称),其中填充了一个只显示该信息的表。我只能让属列正确填充,但不能正确填充物种/名称列。
工作代码 - 正确显示一列:
更新.html
<!--this is for the table -->
<div class="container">
<div class="row">
<div class="col">
<table id="table" border="1">
<tr>
<th class="cell">Genus</th>
<th class="cell">Species</th>
<th class="cell">Comname</th>
</tr>
<!--the next line with the python code works as long as you only want the genus information-->
{% for g in genus_update %}
<tr>
<td class="cell">{{g}}</td>
<!--<td class="cell">{{g}}</td>-->
<!--<td class="cell">{{c}}</td>-->
</tr>
{% endfor %}
</table>
</div>
<div class="col">
<!--the right column so that everything is lined up on the left side-->
</div>
</div>
</div>
尝试为其他人使用 for 循环会破坏页面(不确定为什么):
{% for s in species_update %}
<tr>
<td class="cell">{{s}}</td>
</tr>
{% endfor %}
{% for c in comname_update %}
<tr>
<td class="cell">{{c}}</td>
</tr>
{% endfor %}
蟒蛇.py:
from flask import Flask, render_template, request, g
import sqlite3
app = Flask (__name__)
# conn = sqlite3.connect('flowers.db')
# c = conn.cursor()
DATABASE = 'flowers.db'
def get_db():
db = getattr(g, '_database', None)
if db is None:
db = g._database = sqlite3.connect(DATABASE)
return db
@app.teardown_appcontext
def close_connection(exception):
db = getattr(g, '_database', None)
if db is not None:
db.close()
@app.route('/')
def index():
c = get_db().cursor()
c.execute('SELECT COMNAME FROM FLOWERS')
all_flowers = c.fetchall()
return render_template("index.html", all_flowers=all_flowers)
慕哥9229398
狐的传说
拉丁的传说
相关分类