我具有長頸瓶的應用程序,查詢一個SQLite數據庫:從燒瓶稱爲sqlite的分貝僅返回變量,而不是值
@app.route('/<subject_id>')
def subject_id_lookup(subject_id):
entries = query_db('select visitdt, cvnotes from exam where id = ?',
[subject_id], one=True)
return render_template('show_results.html', entries = entries)
我用的燒瓶功能從文檔大致維持不變,包括query_db()
def query_db(query, args=(), one = False):
"""Queries the database and returns a list of dictionaries"""
cur = g.db.execute(query, args)
rv = [dict((cur.description[idx][0], value)
for idx, value in enumerate(row)) for row in cur.fetchall()]
return (rv[0] if rv else None) if one else rv
終於這是我的show_results.html文件:
{% extends "layout.html" %}
{% block body %}
<ul class=entries>
{% for entry in entries %}
<li><h2>{{ entry }}</h2>
<br>
{% else %}
<li><em>No entry here</em>
{% endfor %}
</ul>
{% endblock %}
查詢運行正常但除了變量名稱visitdt
& cvnotes
之外沒有任何東西被返回。當我將上面的行更改爲<li><h2>{{ entry.cvnotes }}</h2>
時,它不返回任何內容。如何修改我的查詢以顯示我的subject_id_lookup()
函數的結果?