【发布时间】:2020-09-21 07:29:51
【问题描述】:
我想将每个单选按钮选择存储为一个数组。
例如,给定 2 个单选按钮,如果用户 a 选择第一个,然后选择第二个,然后再次选择第一个,我想要一个 [1,2,1] 数组。
这里是questions.html:
<html>
<head>
<title></title>
</head>
<body>
{% for post in posts %}
<h1>Question {{ post.Number }}</h1>
<h2> {{ post.Question }}</h2>
{% for choice in post.Choices %}
<form>
<input type="radio" name="choice" id="{{ post.Number }}{{ choice[0] }}" value="{{ choice[0] }}"> {{ choice[1] }}</input><br>
{% endfor %}
</form>
{% endfor %}
</body>
</html>
这里是flask_main.py:
from flask import Flask, render_template
import statics
app = Flask(__name__)
post = [
{'Number': '1',
'Statement': 'the question',
'Choices': [('a', 'words'),
('b', 'words')]
},
{'Number': '2',
'Statement': 'the question',
'Choices': [('a', 'words'),
('b', 'words')]
}
]
@app.route('/')
@app.route("/questions")
def questions():
return render_template('questions.html', posts=post)
if __name__ == '__main__':
app.run(debug=True)
【问题讨论】:
标签: javascript python html flask jinja2