I am using WTForms for the first time. Using WTForms to validate POST requests in Tornado Below is my forms forms.py
class UserForm(Form):
user = TextField('user', [validators.Length(min=23, max=23)])
In the tonado handler I have
def post(self):
form = UserForm(self.request.body)
The error message i get is: formdata should be a multidict-type wrapper that supports the 'getlist' method"
How could I make this work?
I didn't find replacing a basic html form contained within a Tornado template with a WTForms form as intuitive as I might have hoped.
Here's an example of a very simple form using
wtforms-tornado
:The template:
The app code:
wtforms-tornado 0.0.1
WTForms extensions for Tornado.
WTForms-Tornado
You'll need an object that can translate the Tornado form object into something WTForms expects. I use this:
Then in your base handler, you'd do something like:
Note: I think this adapted from a mailing list topic on this subject.