Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Nenad Ristov
Nenad Ristov
4,647 Points

I am getting โ€œType errorโ€ on flask form, and I don't how to fix it

I am trying to make flask form. I am using validation on every form but I get Type error on only one. TypeError: init() got an unexpected keyword argument 'validators'

I removed that form and it worked perfectly but when I put it back I get the error again.

def model_postoi(form, field):
    if User.select().where(User.model==field.data).exists():
        raise ValidationError("Modelot Postoi")

class Vnesuvanje(Form):
    model=StringField(
        "Model",
        validators=[
            DataRequired(),
            model_postoi])
    proizvoditel=StringField(
        "Proizvoditel",
         validators=[
            DataRequired()])
    cena=IntegerField(
        "Cena",
        validators=[
            DataRequired()])
    kolicina=IntegerField(
        "Kolicina",
       validators=[
            DataRequired()])

I get the error on the cenaand kolicina form

cena=IntegerField(
        "Cena",
        validators=[
            DataRequired()])
    kolicina=IntegerField(
        "Kolicina",
       validators=[
            DataRequired()])

The full traceback:

Traceback (most recent call last):
  File "C:\Users\risto\Desktop\magacin\forms.py", line 13, in <module>
    class Vnesuvanje(Form):
  File "C:\Users\risto\Desktop\magacin\forms.py", line 29, in Vnesuvanje
    DataRequired(),
TypeError: __init__() got an unexpected keyword argument 'validators'

Please, someone, help me. Thank you in advance