O'Reilly logo

Mastering Flask by Jack Stouffer

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

Flask Login

To start using Flask Login, it needs to be downloaded first:

$ pip install flask-login

The main Flask Login object is the LoginManager object. Like the other Flask extensions, initialize the LoginManager object in extensions.py:

from flask.ext.login import LoginManager
…
login_manager = LoginManager()

There are some configuration options that need to be changed on the object:

login_manager.login_view = "main.login"
login_manager.session_protection = "strong"
login_manager.login_message = "Please login to access this page"
login_manager.login_message_category = "info"

@login_manager.user_loader
def load_user(userid):
    from models import User
    return User.query.get(userid)

The preceding configuration values define which view should be treated ...

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