A
A
Alexander2015-03-03 18:01:55
Flask
Alexander, 2015-03-03 18:01:55

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

2 answer(s)
G
German Jet, 2015-03-03
@GeraJet

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()])

views.py
...
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)

What is the problem?

A
asantat, 2018-05-21
@asantat

Before posting a question, just look at the documentation. It is indicated there. WTForms is a popular Flask solution, so the documentation is easy to find.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question