Building Flask forms with Flask-WTF
Flask-WTF is a flexible Flask extension module that uses classes to create forms, form fields, validations, and form renditions. It uses the WTForms
library to enhance form handling in Flask applications. Instead of using HTML markup, Flask-WTF provides the necessary utilities to manage the web forms in a Pythonic way through form models.
Creating the form models
Form models must extend the FlaskForm
core class to create and render the <form>
tag. Its attributes correspond to the form fields defined by the following helper classes:
StringField
: Defines and creates a text input field that accepts string-typed data.IntegerField
: Defines and creates a text input field that accepts integers.DecimalField
: Defines and creates a text input field that asks for decimal values.DateField
: Defines and creates a text input field that supportsDate
types with the default format ofyyyy-mm-dd
.EmailField
: Defines and creates...