我正在尝试从表单中接收变量,但是我使用了try和except,但发现没有收到任何内容。这是我的代码:
使用Flask的Python:
@app.route('/topic/<topic>', methods=['POST', 'GET'])
def questions(topic):
g.db = connectDB()
query = 'SELECT question, questionNumber FROM questions WHERE topic=\"' + topic + '\"'
try:
thisQuestion = request.form['thisQuestion'] + 1
print 'try'
except:
thisQuestion = 0
print 'except'
cur = g.db.execute(query)
questions = [dict(question=row[0], questionNumber=row[1]) for row in cur.fetchall()]
question = questions[thisQuestion]['question']
questionNumber = questions[thisQuestion]['questionNumber']
g.db.close()
return render_template('topic.html', topic=topic, subject='chemistry', question=question, qn=questionNumber, thisQuestion=thisQuestion)
HTML表单
<form method="POST" action="{{ url_for('questions', topic=topic, thisQuestion=thisQuestion) }}">
我想要发生的是,thisQuestion变量在每个会话的0开始,但每次提交表单时将其值增加1。有什么想法吗?
答案 0 :(得分:0)
这是因为以下事情之一:
name
标记name
标签(区分大小写?)