login_user, logout_user, and Sessions
Sign users in and out of a session.
Logging Someone In
Once a password checks out, you tell Flask-Login the user is signed in by calling login_user. That single call sets up the session for you.
from flask_login import login_user
login_user(user)A Typical Login Route
In a login view you find the user, verify the password, then call login_user. After that, redirect them to a real page like the dashboard.
if user and user.check_password(pw):
login_user(user)
return redirect(url_for("dashboard"))All lessons in this course
- Hash Passwords, Never Store Plaintext
- User Loader and the UserMixin
- login_user, logout_user, and Sessions
- Protect Views with login_required