2

I want to get user input and validate if it is correct or not in the backend... There is something missing but I am not able to figure it out:

run.py code:

@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 code:

<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

1 Answer 1

1

Missing method="POST" in

game_page.html:

<form class="form" autocomplete="off" spellcheck="false" method="POST"> <label for="name">Write down your answer</label> <input type="text" class="form-control" autofocus="autofocus" id="answer" name="answer"> </form> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.