anfederico / flaskex

Simple flask example for quick prototypes and small applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WTForms errors

ScottPriestley opened this issue · comments

The code in forms.py needs updated as below due to changes in form validation from WTForms.

Replace:

-- coding: utf-8 --

from wtforms import Form, StringField, validators

class LoginForm(Form):
username = StringField('Username:', validators=[validators.required(), validators.Length(min=1, max=30)])
password = StringField('Password:', validators=[validators.required(), validators.Length(min=1, max=30)])
email = StringField('Email:', validators=[validators.optional(), validators.Length(min=0, max=50)])

With:

-- coding: utf-8 --

from wtforms import Form
from wtforms import (StringField)
from wtforms.validators import InputRequired, Length

class LoginForm(Form):
username = StringField('Username:', validators=[InputRequired(), Length(min=5, max=30)])
password = StringField('Password:', validators=[InputRequired(), Length(min=5, max=30)])
email = StringField('Email:', validators=[Length(min=0, max=30)])

Thanks - would you mind submitting a pull request?

I was not able to get the code to work with the above solution, but after checking wtforms documentation, this worked:

REPLACE THE FOLLOWING:
class LoginForm(Form): username = StringField('Username:', validators=[validators.required(), validators.Length(min=1, max=30)]) password = StringField('Password:', validators=[validators.required(), validators.Length(min=1, max=30)]) email = StringField('Email:', validators=[validators.optional(), validators.Length(min=0, max=50)])
WITH:
class LoginForm(Form): username = StringField('Username:', validators=[validators.InputRequired(), validators.Length(min=5, max=30)]) password = StringField('Password:', validators=[validators.InputRequired(), validators.Length(min=5, max=30)]) email = StringField('Email:', validators=[validators.Length(min=0, max=30)])