WTForms error: “object.__new__() takes no parameters”, when setting additional kwargs
-
12-12-2019 - |
Question
Gathering from what I've seen, I'm guessing you're supposed to pass kwargs to WTForms widget and it will add them as attributes to the tag, right? Like so?
from wtforms import Form, TextAreaField, validators
from wtforms.widgets import TextArea
class ContactForm(Form):
body = TextAreaField('Message', [validators.Required()], widget=TextArea(rows=25, cols=50))
Well, what I get in my console is the following:
TypeError: object.__new__() takes no parameters
After a few hours of research and trepidation, I'm not quite sure what to make of this error. The TextArea widget source says the following:
rows
andcols
ought to be passed as keyword args when rendering.
Seems like it should be pretty straightforward.
I'm using Python 2.7 in App Engine, along with Flask, if that helps any. I'm using the latest version of WTForms, 1.0.1 as of the time of writing.
Thanks in advance!
Solution
You can set cols and rows in your HTML:
{{form.text(cols="45", rows="10", placeholder=_('Please describe in a few simple sentences'))|safe}}
And then call your widget with no parameters ()