-3

classes.py

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.

Javad
  • 2,033
  • 3
  • 13
  • 23
  • Please don't double-space everything. It makes it harder to read without lots of scrolling. – Barmar Nov 01 '22 at 17:40
  • 3
    `validate_on_submit` is a method of `FlaskForm`, not `Form`. – Barmar Nov 01 '22 at 17:43
  • Sorry for the inconvenience as this is my first posting here, may I know where can I make a change @Barmar? –  Nov 01 '22 at 17:46
  • `class CreateTask(Form):` should be `class CreateTask(FlaskForm):` and similar for the other classes. – Barmar Nov 01 '22 at 17:48
  • See the example in the [documentation](https://flask-wtf.readthedocs.io/en/1.0.x/quickstart/?highlight=validate_on_submit#validating-forms) – Barmar Nov 01 '22 at 17:48

1 Answers1

1

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!

Zach J.
  • 366
  • 6
  • But sir even after updating the classes.py file, I'm still getting an error as - "redis.exceptions.ResponseError: WRONGTYPE Operation against a key holding the wrong kind of value" may I know how to resolve this? ~ Thank you –  Nov 01 '22 at 18:09
  • That's a different error not related to this question. But if you pop that error into google, this is the first hit I get - https://stackoverflow.com/questions/37953019/wrongtype-operation-against-a-key-holding-the-wrong-kind-of-value-php – Zach J. Nov 01 '22 at 18:15
  • I was working on this for continously 6 hours and still haven't been able to solve all the errors and run, if you don't mind could you pls guide me on how to resolve this as I've uploaded my whole code of it? Would really appreciate it ~ Thank you –  Nov 01 '22 at 18:26
  • Working on something for a long time with no progress can be extremely frustrating - sometimes it's not bad to take a break for a bit and then come back to it. As for the code itself, any time you get an error, pop it into google to see if you can find the root cause of the issue like I did with your Redis error. Troubleshooting is a hard skill to develop, but will get easier as you keep working on it! – Zach J. Nov 01 '22 at 20:18