Created
September 8, 2023 11:02
-
-
Save aeruo/831a095d714c115e9dee2c39bb3070d4 to your computer and use it in GitHub Desktop.
Python decorator function to require login.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def login_required(f): | |
""" | |
Decorate routes to require login. | |
http://flask.pocoo.org/docs/1.0/patterns/viewdecorators/ | |
""" | |
@wraps(f) | |
def decorated_function(*args, **kwargs): | |
if session.get("user_id") is None: | |
return redirect("/") | |
return f(*args, **kwargs) | |
return decorated_function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment