Я изо всех сил пытаюсь передать результаты моего оператора SELECT всем моим представлениям. Я использую флягу и 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))