Answer the question
In order to leave comments, you need to log in
Flask how to handle select field?
Hello, I can’t understand how to process select fields in flask? Please give literature, where it is indicated that when the button was clicked, the selectable list was processed.
Answer the question
In order to leave comments, you need to log in
forms.py
# -*- coding: utf-8 -*-
from flask.ext.wtf import Form
from wtforms import TextField, SelectField
from wtforms.validators import Required
class WeatherAddForm(Form):
sost = SelectField("Состояние: ", choices=[
("ясно", "ясно"),
("пасмурно", "пасмурно"),
("туман", "туман"),
("дождь", "дождь"),
("снег", "снег")])
temp = TextField('Temp', [Required()])
...
def create():
form = WeatherAddForm()
if form.validate_on_submit():
rec = Weather(
sost = request.form['sost'],
temp = request.form['temp'])
db.session.add(rec)
db.session.commit()
flash(u'Сведения обновлены!')
return redirect(url_for('.index'))
...
return render_template("weather/create.html",
form = form)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question