O'Reilly logo

Learning Flask Framework by Charles Leifer, Matt Copperwaite

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating comments using AJAX

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)]) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required