November 2015
Beginner
250 pages
5h 16m
English
In order to allow users to post comments, we first need a way to capture their input, which we will do by creating a Form class with wtforms. This form should allow users to enter their name, email address, an optional URL, and their comment.
In the forms module in the entries blueprint, add the following form definition:
class CommentForm(wtforms.Form): name = wtforms.StringField('Name', validators=[validators.DataRequired()]) email = wtforms.StringField('Email', validators=[ validators.DataRequired(), validators.Email()]) url = wtforms.StringField('URL', validators=[ validators.Optional(), validators.URL()]) body = wtforms.TextAreaField('Comment', validators=[ validators.DataRequired(), validators.Length(min=10, max=3000)]) ...