質問:htmlにはループがあり、サイクルごとにname = "answer []"という入力があります。私がしたいのは、pythonで入力からすべてのデータを受け取ることです。私の方法は "answer = request.form [" answer [] "]"ですが、最初の回答のみを受け取ります。すべての回答をhtmlから受け取るにはどうすればいいですか。htmlに同じ名前のいくつかの入力がある場合、pythonの受信方法
HTML:
<!doctype html>
<html>
<head>
<title>fill_out page </title>
</head>
<body>
<h1> answer page </h1>
<Form method="POST">
{% for question in content %}
Question{{ loop.index }} :     {{ question }}<br></br>
<input name="answer[]" placeholder="Enter your answer"/><br></br>
{% endfor %}
<button type="submit" name="bt">submit</button><br></br>
</Form>
<h2> if you want to switch account <a href="./index.html"> resign in</a></h2>
</body>
</html>
のpython:
@app.route("/fill_out.html/<username>",methods=["GET", "POST"])
@app.route("/fill_out.html",methods=["GET", "POST"])
def fill_out(username=None) :
content=find_question()
if request.method=="POST" :
answer=request.form["answer[]"]
print(answer)
return redirect(url_for("congratulations",username=username))
return render_template("fill_out.html",content=content)
あなたは助けることができる場合、私は本当に
私が間違っていない場合は、ウェブサイト**で**あなたがそれを投稿できなかった理由を教えてください! –
なぜ私は投稿できないのではなく、文章は単なる文脈であり、問題はPythonです –
コードが行うべきことをより正確に記述してください。 –