Can anyone tell me why i am getting "NameError: name 'validators' is not defined" in flask? As i am new to flask

B

Benny khatri

Guest
I am using Wt forms in flask i have installed the wtf module and use it to create form but when i try to run the application it is showing that Validators are not defined even though i have imported it correctly. Please check and correct what i am doing wrong with my piece of code. Thanks

I have checked multiple article over the web but nothing solved my problem

from flask_wtf import FlaskForm
from wtforms import StringField,PasswordField,SubmitField,BooleanField
from wtforms.validators import DataRequired, Length, Email, EqualTo

class RegistrationForm(FlaskForm):
username = StringField('Username', validators[DataRequired(),Length(min=2, max=20)])
email = StringField('Email', validators[DataRequired(), Email()])
password = PasswordField('Password', validators[DataRequired()])
confirm_password = PasswordField('Confirm Password', validators[DataRequired(), EqualTo('password')])
submit = SubmitField('Sign Up')

class LoginForm(FlaskForm):
email = StringField('Email', validators[DataRequired(), Email()])
password = PasswordField('Password', validators[DataRequired()])
remember = BooleanField('Remember Me')
submit = SubmitField('Login')


Traceback (most recent call last):
File "app.py", line 2, in <module>
from forms import RegistrationForm, LoginForm
File "/Users/bennykhatri/Practice/Flask/Corey/forms.py", line 5, in <module>
class RegistrationForm(FlaskForm):
File "/Users/bennykhatri/Practice/Flask/Corey/forms.py", line 6, in RegistrationForm
username = StringField('Username', validators[DataRequired(), Length(min=2, max=20)])
NameError: name 'validators' is not defined

Continue reading...
 
Top