0PricingLogin
Flask Academy · Lesson

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

  1. Hash Passwords, Never Store Plaintext
  2. User Loader and the UserMixin
  3. login_user, logout_user, and Sessions
  4. Protect Views with login_required
← Back to Flask Academy