Пример формы wtforms и её использование в Flask приложении


--- forms.py
  • forms.py
from wtforms import (
    validate,
    Form,
    TextField
)


class NewForm(Form):
    name = TextField('Логин', [validators.Length(min=4, max=25)])


@app.route('/add', methods=['GET', 'POST'])
    form = NewForm(request.form)
    if request.method == 'POST':
        if form.validate():
            app.logger.info(form.name.data)
            return redirect('/user/{}'.format(form.name.data), code=302)
    body = render_template('user_add.html', form=form)
    return body
© RemiZOffAlex