我在烧瓶中使用Wt表单,我已经安装了wtf模块并使用它来创建表单,但是当我尝试运行该应用程序时,这表明即使我已正确导入它也未定义Validator。 请检查并更正我的代码片段在做什么。 谢谢
我已经在网上检查了多篇文章,但没有解决我的问题
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
答案 0 :(得分:0)
不,您还没有完成
import validators
这样做的时候
from validators import x, y, z
那么实际上只导入x
,y
和z
。