Skip to content
Advertisement

has no attribute validate_on_submit: How to use wtforms-alchemy’s ModelForm in a flask handler / view

I’m trying to switch from wtforms.ext.sqlalchemy.orm import model_form to using wtforms_alchemy ModelForm:

JavaScript

I’m failing miserably… and I’ve been unsuccessful searching for a working example of that uses wtforms_alchemy which shows both the handler and the model.

Using model_form works for me: Here’s my working code using model forms:

The model script (python):

JavaScript

The handler script (python, flask, model_form):

JavaScript

The template (uses mako):

JavaScript

When I try to change my handler script page over to using ModelForm with this code (below) I get a ‘TestForm’ object has no attribute ‘validate_on_submit’ error

The handler script (python, flask, ModelForm):

JavaScript

What am I missing?

Advertisement

Answer

Nevermind.

Although I had tried using

JavaScript

prior to this post, it decided to work when I put it back, but after the ModelForm import instead of before it.

Whatever.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement