【发布时间】:2019-11-23 21:30:42
【问题描述】:
当用户单击提交按钮时,我试图从下拉列表中传递所选项目。
下面是 HTML 代码
<form action="/switchinfo" method="post">
<div align="center" id="mainselection">
<select name="sites" method="GET" action="/">
<option selected="selected">Select an the site</option>
{% for site in sites[0:] %}
<option value="{{site}}">{{site}}</option>
{% endfor %}
</select>
</div>
<button class="button execute" name="submit" value="submit">Submit</button>
</form>
这是python代码
@app.route('/', methods=['GET', 'POST'])
def index():
sites = ['DC1', 'DC2', 'DC3', 'DC4']
return render_template('index.html', sites=sites)
@app.route('/switchinfo', methods=['POST'])
def switchinfo():
gather = request.form["site"]
return render_template("switchinfo.html",gather=gather)
if __name__ == "__main__":
app.run()
收到错误werkzeug.exceptions.BadRequestKeyError。
感谢您的帮助
【问题讨论】: