我想获取用户输入并验证后端中的输入是否正确... 缺少一些东西,但我无法弄清楚:
run.py代码:
@app.route('/game', methods = ["GET","POST"])
def game():
global answer_number
global user_correct
global user_wrong
with open ("data/riddles.json", "r") as jason_data:
data = json.load(jason_data)
if request.method == "POST":
user_answer.append(request.form["answer"])
if user_answer [-1] == data[answer_number]["answer"]:
answer_number += 1
user_correct += 1
else:
user_wrong += 1
print (answer_number, user_correct, user_wrong)
return render_template("game_page.html", user_list = user_list, riddles_data = data, user_answer=user_answer, answer_number=answer_number)
game_page.html代码:
<form class="form" autocomplete="off" spellcheck="false">
<label for="name">Write down your answer</label>
<input type="text" class="form-control" autofocus="autofocus" id="answer" name="answer">
</form>
答案 0 :(得分:0)
在
中缺少method =“ POST”game_page.html:
Pattern.COMMENTS