Python Flask commit button issue

Python Flask commit button issue … here is a solution to the problem.

Python Flask commit button issue

The “Send…”

button doesn’t work, the index page is working, the dropdown menu works fine, but nothing happens when I click “Send…” (Result.html Yes, but of course empty) Any idea, what is the problem?

I have these .py files:

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)

Of course, there are two more .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>

Solution

Replace your HTML with this HTML. You need to place the submit button inside the form label for it to 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>

Related Problems and Solutions