0
我正在努力將SELECT語句的所有結果傳遞給我的視圖。我正在使用flask和MySQLdb。什麼是適當的語法來顯示我的表格到我的HTML頁面的所有結果?我很想通過一個清單,但無法爲此列出語法。使用Flask將列表表格結果轉換爲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))