python - Why the expected instance 'user' is a class? -


recently i'm learning flask, , there bug confused me 2 days:
when try login in login_user,it raises typeerror: __init__() takes 1 2 positional arguments 3 given
user in models.py:

class user(usermixin, db.model):     __tablename__ = 'users'     id = db.column(db.integer, primary_key=true)     email = db.column(db.string(140), unique=true, index=true)     username = db.column(db.string(80), unique=true, index=true)     password_hash = db.column(db.string(128))     confirmed = db.column(db.boolean, default=false)     role_id = db.column(db.integer, db.foreignkey('roles.id')) 


loginform in forms.py:

class loginform(flaskform):     email = stringfield('邮箱', validators=[datarequired(), length(1, 64), email])     password = passwordfield('密码', validators=[datarequired()])     remember_me = booleanfield('记住我')     submit = submitfield('登陆') 


/login in views.py:

@auth.route('/login', methods=['get', 'post']) def login():     form = loginform()     if form.validate_on_submit():         user = user.query.filter_by(email=form.email.data).first()         if user not none , user.verify_password(form.password.data):             login_user(user, remember=form.remember_me.data)             return redirect(request.args.get('next') or url_for('main.index'))         flash('用户名或密码错误')     return render_template('auth/login.html', form=form) 


after viewing source code of login_user in flask_login,i got positional argument user should object,so run python manage.py shell,but got those:

>>> user = user(username='aaa') >>> type(user) <class 'app.models.user'> >>> user = user.query.filter_by(email='arszrc@gmail.com').first() >>> user <user 'arszrc'> >>> type(user) <class 'app.models.user'> 

is there tell me why type of user class instead of object?

error:

traceback (most recent call last):   file "/users/arszrc/pycharmprojects/pyflask3.5/lib/python3.5/site-packages/flask/app.py", line 2000, in __call__     return self.wsgi_app(environ, start_response)   file "/users/arszrc/pycharmprojects/pyflask3.5/lib/python3.5/site-packages/flask/app.py", line 1991, in wsgi_app     response = self.make_response(self.handle_exception(e))   file "/users/arszrc/pycharmprojects/pyflask3.5/lib/python3.5/site-packages/flask/app.py", line 1567, in handle_exception     reraise(exc_type, exc_value, tb)   file "/users/arszrc/pycharmprojects/pyflask3.5/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise     raise value   file "/users/arszrc/pycharmprojects/pyflask3.5/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app     response = self.full_dispatch_request()   file "/users/arszrc/pycharmprojects/pyflask3.5/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request     rv = self.handle_user_exception(e)   file "/users/arszrc/pycharmprojects/pyflask3.5/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception     reraise(exc_type, exc_value, tb)   file "/users/arszrc/pycharmprojects/pyflask3.5/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise     raise value   file "/users/arszrc/pycharmprojects/pyflask3.5/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request     rv = self.dispatch_request()   file "/users/arszrc/pycharmprojects/pyflask3.5/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request     return self.view_functions[rule.endpoint](**req.view_args)   file "/users/arszrc/pycharmprojects/flasky/app/auth/views.py", line 15, in login     if form.validate_on_submit():   file "/users/arszrc/pycharmprojects/pyflask3.5/lib/python3.5/site-packages/flask_wtf/form.py", line 161, in validate_on_submit     return self.is_submitted() , self.validate()   file "/users/arszrc/pycharmprojects/pyflask3.5/lib/python3.5/site-packages/wtforms/form.py", line 310, in validate     return super(form, self).validate(extra)   file "/users/arszrc/pycharmprojects/pyflask3.5/lib/python3.5/site-packages/wtforms/form.py", line 152, in validate     if not field.validate(self, extra):   file "/users/arszrc/pycharmprojects/pyflask3.5/lib/python3.5/site-packages/wtforms/fields/core.py", line 204, in validate     stop_validation = self._run_validation_chain(form, chain)   file "/users/arszrc/pycharmprojects/pyflask3.5/lib/python3.5/site-packages/wtforms/fields/core.py", line 224, in _run_validation_chain     validator(form, self) typeerror: __init__() takes 1 2 positional arguments 3 given 

try call email validator email():

class loginform(flaskform):     email = stringfield('邮箱', validators=[datarequired(), length(1, 64), email()]) 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -