I am new too Flask. I receive 'None' instead of value from select field as response. So will be thankful for help!
Here is my layout:
<form method="post">
<!-- select -->
<div class="form-group mt-4">
<legend for="Sel">Choose criteria to sort</legend>
<select class="custom-select" id="Sel" name="sel"> <!-- multiple -->
{% for field in form.select %}
<option value="{{ field }}"></option>
{% endfor %}
</select>
</div>
<!-- submit -->
{{form.submit(class="btn btn-primary")}}
</form>
And that`s my view:
from flask import Flask, render_template, request
from wtforms import Form, SelectField, SubmitField
app = Flask(__name__)
sel_choice = [
('sex', 'gender of the person interviewed '),
('city', 'city where pool took place'),
('emotion', 'emotional characteristic of person`s comment'),
('month', 'month of poll'),
('poll_time', 'poll time')
]
class ChoiceForm(Form):
select = SelectField(u'Criteria', choices=sel_choice)
submit = SubmitField(label='apply')
@app.route('/', methods=['POST', 'GET'])
def sel():
form = ChoiceForm(request.form)
if request.method == 'POST':
print(form.select.data)
return render_template('forms.html', form=form)
That`s what I receive from server:
- Serving Flask app "test.py" (lazy loading)
- Environment: development
- Debug mode: on
- Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
- Restarting with stat
- Debugger is active!
Debugger PIN: 231-471-963
None
127.0.0.1 - - [17/Oct/2019 13:00:55] "POST / HTTP/1.1" 200 -