How to render my TextArea with WTForms?

TextArea field can be also implemented without any widgets:

forms.py

from wtforms import Form, TextField, TextAreaField

class ContactForm(Form):
    name = TextField('Name')
    email = TextField('Email Address')
    body = TextAreaField('Message Body')

template.html

... 
    <form method="POST" action="">
        {{ form.csrf_token }}
        {{ form.name.label }} {{ form.name(size=30) }} <br/>
        {{ form.email.label }} {{ form.email(size=30) }} <br/>
        {{ form.body.label }} {{ form.body(cols="35", rows="20") }} <br/>
        <input type="submit" value="Submit"/>
    </form>
...

Very old question, but since the WTF-Form documentation isn't clear I'm posting my working example. OP, hope you are not still working on this. :-)

form

from flask_wtf import Form
from wtforms.fields import StringField
from wtforms.widgets import TextArea

class PostForm(Form):
    title = StringField(u'title', validators=[DataRequired()])
    body = StringField(u'Text', widget=TextArea())

template

{% extends "base.html" %}
{% block title %}Create Post{% endblock %}
{% block content %}
<H3>Create/Edit Post</H3>
<form action="" method=post>
   {{form.hidden_tag()}}
   <dl>
      <dt>Title:
      <dd>{{ form.title }}
      <dt>Post:
      <dd>{{ form.body(cols="35", rows="20") }}}
   </dl>
   <p>
      <input type=submit value="Publish">
</form>
{% endblock %}

There is no need to update the template for this issue. You can set the rows and cols in the definition of TextAreaField. Here is the sample: \

class AForm(Form):
     text = TextAreaField('Text', render_kw={"rows": 70, "cols": 11})

For render_kw, if provided, a dictionary which provides default keywords will be given to the widget at render time.

Tags:

Python

Wtforms