“发送...”按钮不起作用,索引页面正在运行,下拉菜单确定,但是当我点击“发送...”时没有任何反应。 (Result.html没问题,但当然空了)任何想法,问题是什么?
我有这些.py文件:
from flask import Flask, request, render_template
from flask_wtf import Form
from flask_wtf import FlaskForm
app = Flask(__name__)
@app.route('/', methods=['POST', 'GET'])
def index():
return render_template('index.html')
@app.route('/result/', methods=['POST', 'GET'])
def result():
vehicle = request.form.get('wine')
year = request.form.get('year')
return render_template('result.html', vehicle=vehicle, year=year)
当然还有两个.html。的index.html:
<!DOCTYPE html>
<html>
<body>
<h1>Submitting</h1>
<form action="/result" method="POST">
<label for="wine">wine</label>
<select id="wine" name="wine">
<option>red</option>
<option>white</option>
<option>rose</option>
</select>
<label for="year">Year</label>
<select id="year"name="year">
<option>1972</option>
<option>1999</option>
<option>2010</option>
</select>
</form>
<br>
<button type="submit" value="submit">send...</button>
</body>
</html>
result.html:
<!DOCTYPE html>
<html>
<body>
{{ vehicle }} {{ year }}
</body>
</html>
答案 0 :(得分:1)
也许您需要将button
放在form
标签中?
<form action="/result" method="POST">
...
<button type="submit" value="submit">send...</button>
</form>
答案 1 :(得分:1)
用此HTML替换您的HTML。你需要在表单标签中放置提交按钮才能使其正常工作。
<body>
<h1>Submitting</h1>
<form action="/result" method="POST">
<label for="wine">wine</label>
<select id="wine" name="wine">
<option>red</option>
<option>white</option>
<option>rose</option>
</select>
<label for="year">Year</label>
<select id="year"name="year">
<option>1972</option>
<option>1999</option>
<option>2010</option>
</select>
<button type="submit" value="submit">send...</button>
</form>
<br>
</body>
</html>