Reputation: 59
The "send..." button is not working, index page is running, drop-down menu ok, but when I click the "send..." nothing happen. (Result.html is ok, but empty of course) Any idea, what is the problem?
I've got these .py file:
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)
And two .html of course. 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>
The result.html:
<!DOCTYPE html>
<html>
<body>
{{ vehicle }} {{ year }}
</body>
</html>
Upvotes: 3
Views: 2102
Reputation: 874
replace your HTML with this HTML. you need to put submit button inside form tag to make it work.
<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>
Upvotes: 2
Reputation: 7412
maybe you need to put your button
in form
tag ?
<form action="/result" method="POST">
...
<button type="submit" value="submit">send...</button>
</form>
Upvotes: 1