In order to manage form rendering and validation, we will use another Flask plugin called wtforms. This plugin requires that the form is defined in a dedicated class, so let's go and create a login form. This form requires the following:
- A username/login: This is a required text input that can be created with the following line:
login = StringField('Login', validators=[DataRequired()])
- A password: This is also a required text input with a hidden value (we do not want our neighbor to read the password on the screen). On top of StringField with a DataRequired validator, we will also specify a custom widget for this field:
password = StringField('Password', validators=[DataRequired()],
widget=PasswordInput(hide_value=False)
)
- A submit button:
submit = SubmitField('Submit')
The full code for the login form is as follows:
class LoginForm(FlaskForm):
login = StringField('Login',...