在python中检索数据库结果

2024-10-01 11:27:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用html页面在网页中显示查询结果。我只能显示列中的第一行,但我需要显示所有行行。请建议:

def formval():
# --connection syntax here--
cursor = connection.cursor()
if request.method == 'POST':
    x = request.form['weekno']
    cursor.execute("SELECT Document FROM Backlog where custno=?",x)
    result = cursor.fetchall()
    return render_template('home.html',weekno=result)

home.html 
{% for docno in weekno %}
  <p>{{ docno }}</p>
  {% endfor %}

上面是我在html页面中用来捕获数据库结果的一段代码。你知道吗

谢谢!你知道吗


Tags: 网页homehererequestdefhtml页面result