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 ...
Get Mastering Flask 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.