我正在尝试在forms.py
文件中导入使用Flask-WTF创建的表单,但由于某些原因,我遇到导入错误:
ImportError: cannot import name 'Permission' from 'website.forms' (C:\Users\moti9\Desktop\website\website\forms.py)
我当时在想也许我有一个循环导入问题,但是我似乎找不到问题,因为我可以从完全相同的文件中导入另一种表格。
forms.py:
from wtforms.validators import DataRequired, length, email, equal_to, ValidationError
from wtforms import StringField, PasswordField, BooleanField, RadioField, SubmitField
from flask_wtf import FlaskForm
from flask_wtf.file import file_allowed, FileField
class Registration(FlaskForm):
alredy_exist='alredy exists, if you alredy have a user press' #a message to present when a Unique validator activates
username = StringField('Username:', validators=[DataRequired(), length(min=4, max=20), Unique(User.username, db.session, message='Username {}'.format(alredy_exist))])
email = StringField('Email', validators=[DataRequired(), email(), Unique(User.email, db.session, message='Email {}'.format(alredy_exist))])
password = PasswordField('Password:', validators=[DataRequired(), length(min=6, max=12)])
#repeat_password = PasswordField('Repeat password', validators=[equal_to('password', 'passwords must match')])
submit = SubmitField('Register')
class Permission(FlaskForm):
create_post = BooleanField('create_post')
delete_post = BooleanField('delete_post')
edit_post = BooleanField('edit_post')
delete_user = BooleanField('delete user')
view_scripts = BooleanField('view_scripts')
admin = BooleanField('admin')
我可以导入Registration
,但不能导入权限,而我只是想不明白为什么。
谢谢。