Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flask wtform TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given

I am having troubles with form validation. The country list is generated correctly, and previous forms worked fine. It is only breaking in POST requests.

Here is my forms.py:

from wtforms import Form, BooleanField, SelectField, \
                    StringField, PasswordField, SubmitField, validators, \
                    RadioField
from ..models import User
from pycountry import countries
...
## Account settings
# We get all COUNTRIES
COUNTRIES = [(c.name, c.name) for c in countries]
# edit profile
class ProfileForm(Form):
    username = StringField('name',[validators.Length(min=1, max=120), validators.InputRequired])
    email = StringField('email', [validators.Length(min=6, max=120), validators.Email()])
    company = StringField('name',[validators.Length(min=1, max=120)])
    country = SelectField('country', choices=COUNTRIES)
    news = BooleanField('news')

and here is the view:

@user.route('/profile/', methods=['GET', 'POST'])
@login_required
def profile():
    userid = current_user.get_id()
    user = User.query.filter_by(id=userid).first_or_404()
    print(user)
    form = ProfileForm(request.form)
    if request.method == 'POST' and form.validate():
        user.username = form.username.data
        ...
        return render_template('settings.html', form=form )
    else:
        form.username.data = user.username
        ...
        return render_template('settings.html', form=form )
like image 309
jmrueda Avatar asked May 10 '17 11:05

jmrueda


1 Answers

It should be validators.InputRequired() instead of validators.InputRequired. Thanks @jackevans

like image 151
jmrueda Avatar answered Oct 28 '22 02:10

jmrueda