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

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

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