WTForms-How to prepopulate a textarea field?
For textarea
widgets, you set the default content with the default
argument in your field constructors.
class YourForm(Form): your_text_area = TextAreaField("TextArea", default="please add content")
Then when you render:
{{form.content()}}
WTForms will render the default text. I have not been able to find a way to specify default text for the text area at render time.
I recently had the same problem, I solved it like this:
{% set f = form.content.process_data("please type content") %}{{ form.content() }}
For a test, you can try run the follow snippet:
>>> import wtforms>>> import jinja2>>> from wtforms.fields import TextAreaField>>> class MyForm(wtforms.Form):... content = TextAreaField("Text Area")... >>> t = jinja2.Template("""{% set f = form.content.process_data("please type content") %}... {{ form.content() }}""")>>> >>> t.render(form=MyForm())u'\n <textarea id="content" name="content">please type content</textarea>'