Login and logout views

Users will log into our blogging site using their email and password; so, before we begin building our actual login view, let's start with the LoginForm. This form will accept the username, password, and will also present a checkbox to indicate whether the site should remember me. Create a forms.py module in the app directory and add the following code:

import wtforms
from wtforms import validators
from models import User

class LoginForm(wtforms.Form):
    email = wtforms.StringField("Email",
        validators=[validators.DataRequired()])
    password = wtforms.PasswordField("Password",
        validators=[validators.DataRequired()])
    remember_me = wtforms.BooleanField("Remember me?",
        default=True)

Tip

Note that WTForms also provides an e-mail validator. ...

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.