我正在努力将SELECT all语句结果传递给我的视图。我用的是烧瓶和MySQLdb。从表格到HTML页面显示所有结果的正确语法是什么?我很想传递一个列表,但无法找出语法。在
HTML调用{{ session.qid }}
只是为了测试,没有显示任何内容。在
以下是我目前掌握的python代码:
@app.route('/view_answered/', methods=['GET','POST'])
def view_answered():
error = ''
try:
if request.method == 'POST':
c, conn = connection()
clientcid = session['clientcid']
cursor.execute("SELECT * FROM tickets WHERE cid = 1 AND solved = 0")
results = cursor.fetchall()
x = 0
qid = []
difficulty = []
time_stamp = []
title = []
body = []
for row in results:
qid[x] = row[0]
difficulty[x] = row[3]
time_stamp[x] = row[4]
title[x] = row[6]
body[x] = row[7]
x = x + 1
conn.commit()
c.close()
conn.close()
gc.collect()
session['qid'] = qid
session['difficulty'] = difficulty
session['time_stamp'] = time_stamp
session['title'] = title
session['body'] = body
return redirect(url_for('view_answered'))
else:
error = "Something is aloof."
return render_template("view_answered.html")
except Exception as e:
return(str(e))
用这个代码解决了它,太干净了!在
查看(r[0]、r[2]等,对应于SQL表中的列位置)
^{pr2}$相关问题 更多 >
编程相关推荐