Can anyone pls help me how to resolve this issue?

Question:

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.

Asked By: John Nick

||

Answers:

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!

Answered By: Zach J.
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.