Protect Views with login_required
Gate routes and redirect anonymous users.
Some Pages Need a Guard
A dashboard or settings page should never load for a stranger. You protect such routes so only a logged-in user can reach them.
The login_required Decorator
Flask-Login hands you a one-line gate: the login_required decorator. Stack it on any view and anonymous visitors get bounced away.
from flask_login import login_requiredAll 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