G
G
Gennady2018-06-28 13:07:25
Python
Gennady, 2018-06-28 13:07:25

What's wrong with a flask project?

Hi all!
I'm studying flask from a tutorial on Habré, I ran into such an error, I've been fighting for several days now:

File "c:\users\morozovg\documents\flaskstudyenv\lib\site-packages\wtforms\fields\core.py", line 226, in _run_validation_chain
    validator(form, self)
TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given

The error occurred after I added the form (and an error occurs when submitting the form)
here is the form code (forms.py):
from flask_wtf import FlaskForm
from wtforms import StringField,PasswordField,BooleanField,SubmitField
from wtforms.validators import DataRequired

class LoginForm(FlaskForm):
    username = StringField('Username', validators=[DataRequired])
    password = PasswordField('Password', validators=[DataRequired])
    remember_me = BooleanField('remember Me')
    submit = SubmitField('Sign in')

And the page code (routes.py):
@app.route('/login', methods=['GET','POST'])
def login():
    form = LoginForm()
    if form.validate_on_submit():
        flash('Login requested for user {}, remember_me={}'.format(
            form.username.data, form.remember_me.data))
        return redirect('/index')
    return render_template('login.html', title='Sign in', form=form)

Please tell me where is the mistake. Thank you in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2018-06-28
@genana40

In validators, you need to pass instances of the class, not the class itself:

username = StringField('Username', validators=[DataRequired()])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question