TypeError: __init__() got an unexpected keyword ar

2019-02-27 16:10发布

I can't find out what's the cause of this error

TypeError: __init__() takes at most 2 arguments (3 given)

which is pointing to

@user_blueprint.route('/login', methods=['GET', 'POST'])
def login():
    if g.user.is_authenticated:
        flash("You are already Logged in", 'warning')
        return redirect(url_for('members'))
    error = ""
    form = LoginForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(username=form.username.data).first()
            if user is not None and bcrypt.check_password_hash(user.password, form.password.data):
                login_user(user, remember=form.remember.data)
                flash('You are sucessfuly Logged in', 'success')
                return redirect(url_for('members'))
            else:
                error = "You have entered an incorrect username and password"
    return render_template("front/login.html", forms=form, error=error)

The LoginForm looks like this:

class LoginForm(Form):
    username = StringField("Username", validators=[DataRequired()])
    password = PasswordField('Password', validators=[DataRequired])
    remember = BooleanField("Remember Me", default=False)

Here is the traceback:

  File "/home/afidegnum/gsam/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/afidegnum/gsam/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/home/afidegnum/gsam/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/afidegnum/gsam/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/afidegnum/gsam/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/afidegnum/gsam/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/afidegnum/gsam/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/afidegnum/gsam/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/afidegnum/PycharmProjects/gsam/project/user/views.py", line 79, in login
    if form.validate_on_submit():
  File "/home/afidegnum/gsam/lib/python2.7/site-packages/flask_wtf/form.py", line 166, in validate_on_submit
    return self.is_submitted() and self.validate()
  File "/home/afidegnum/gsam/lib/python2.7/site-packages/wtforms/form.py", line 310, in validate
    return super(Form, self).validate(extra)
  File "/home/afidegnum/gsam/lib/python2.7/site-packages/wtforms/form.py", line 152, in validate
    if not field.validate(self, extra):
  File "/home/afidegnum/gsam/lib/python2.7/site-packages/wtforms/fields/core.py", line 204, in validate
    stop_validation = self._run_validation_chain(form, chain)
  File "/home/afidegnum/gsam/lib/python2.7/site-packages/wtforms/fields/core.py", line 224, in _run_validation_chain
    validator(form, self)
TypeError: __init__() takes at most 2 arguments (3 given)

1条回答
叼着烟拽天下
2楼-- · 2019-02-27 16:23

You didn't call one of your validators:

password = PasswordField('Password', validators=[DataRequired])

Add ():

password = PasswordField('Password', validators=[DataRequired()])
查看更多
登录 后发表回答