【发布时间】:2012-04-17 14:32:19
【问题描述】:
我有一个烧瓶应用程序可以查询一个 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() 函数的结果?
【问题讨论】: