Home > Software engineering >  Can anyone pls help me how to resolve this issue?
Can anyone pls help me how to resolve this issue?

Time:11-02

AttributeError

`` classes.py file

from flask_wtf import Form
from wtforms import TextField, IntegerField, SubmitField

class CreateTask(Form):
    title = TextField('Task Title')
    shortdesc = TextField('Short Description')
    priority = IntegerField('Priority')
    create = SubmitField('Create')

class DeleteTask(Form):
    key = TextField('Task Key')
    title = TextField('Task Title')
    delete = SubmitField('Delete')

class UpdateTask(Form):
    key = TextField('Task Key')
    title = TextField('Task Title')
    shortdesc = TextField('Short Description')
    priority = IntegerField('Priority')
    update = SubmitField('Update')

class ResetTask(Form):
    reset = SubmitField('Reset')

It says - The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.

CodePudding user response:

The error is coming from your run.py file, but the main issue is from classes.py.

In the first line of your main() function:

def main():

    # create form

    cform = CreateTask(prefix='cform')

You create a variable cform from the CreateTask object.

Then, further in your main() function, you have this if statement:

# response

if cform.validate_on_submit() and cform.create.data:

    return createTask(cform)

cform is a CreateTask object made from flask_wtf.Form which does not have a method validate_on_submit().

I checked the API documentation, and the validate_on_submit() only comes from the class flask_wtf.FlaskForm and not flask_wtf.Form

So to solve this, in your classes.py file:

from flask_wtf import Form
from wtforms import TextField, IntegerField, SubmitField

class CreateTask(Form):
    title = TextField('Task Title')
    shortdesc = TextField('Short Description')
    priority = IntegerField('Priority')
    create = SubmitField('Create')

import FlaskForm instead of Form, then update your classes to use FlaskForm -

from flask_wtf import FlaskForm
from wtforms import TextField, IntegerField, SubmitField

class CreateTask(FlaskForm):
    title = TextField('Task Title')
    shortdesc = TextField('Short Description')
    priority = IntegerField('Priority')
    create = SubmitField('Create')

Hope this helps!

  • Related