3 回答

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超6個(gè)贊
解決了
解決方案
html代碼:
{% for g, s, c in genus_flowers%}
<tr>
<td class="cell">{{g}}</td>
<td class="cell">{{s}}</td>
<td class="cell">{{c}}</td>
</tr>
{% endfor %}
蟒蛇代碼:
@app.route('/update')
def update():
c = get_db().cursor()
# this just gets the data from the db
c = get_db().cursor()
c.execute('SELECT GENUS, SPECIES, COMNAME FROM FLOWERS')
genus_flowers = c.fetchall()
return render_template("update.html", genus_flowers=genus_flowers)

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超3個(gè)贊
我知道在 Django 中,python 的另一個(gè) web 框架,你必須引用對象中的字段,而不僅僅是對象本身。因此,如果您執(zhí)行 Select *,而不是 Select 'field':
@app.route('/update')
def update():
c = get_db().cursor()
# this just gets the data from the db
c.execute('SELECT * FROM FLOWERS')
flowers = c.fetchall()
zipped = zip(genus_update, species_update)
return render_template("update.html", flowers=flowers, zipped=zipped)
然后,您可以執(zhí)行以下操作:
<!--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 f in flowers %}
<tr>
<td class="cell">{{ f.genus }}</td>
<td class="cell">{{ f.species }}</td>
<td class="cell">{{ f.comname }}</td>
</tr>
{% endfor %}
</table>
</div>
<div class="col">
</div>
</div>
</div>

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超8個(gè)贊
我不確定這里究竟會發(fā)生什么,但由于我處于這種情況之前,我建議您先測試是否從數(shù)據(jù)庫中獲取數(shù)據(jù),而不是直接檢查 Flask 呈現(xiàn)它的部分。確保傳遞的查詢的數(shù)據(jù)也存在。
希望這將有助于進(jìn)展。
添加回答
舉報(bào)