Created
July 31, 2017 10:46
-
-
Save rana-ahmed/1fb6c4105e1c4d7e750fb9cabd9406ed to your computer and use it in GitHub Desktop.
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(function=None, redirect_field_name=REDIRECT_FIELD_NAME, login_url=None): | |
""" | |
Decorator for views that checks that the user is logged in, redirecting | |
to the log-in page if necessary. | |
""" | |
actual_decorator = user_passes_test( | |
lambda u: u.is_authenticated, | |
login_url=login_url, | |
redirect_field_name=redirect_field_name | |
) | |
if function: | |
return actual_decorator(function) | |
return actual_decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment