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)]) ...
Get Learning Flask Framework now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.