Created
August 17, 2021 07:47
-
-
Save skolo-online/11edb3506eb8a1ef51d024c79650f1c4 to your computer and use it in GitHub Desktop.
Python Django invoicing app - views and decorators
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
from django.contrib.auth.decorators import user_passes_test | |
#Anonymous required | |
def anonymous_required(function=None, redirect_url=None): | |
if not redirect_url: | |
redirect_url = 'dashboard' | |
actual_decorator = user_passes_test( | |
lambda u: u.is_anonymous, | |
login_url=redirect_url | |
) | |
if function: | |
return actual_decorator(function) | |
return actual_decorator | |
def index(request): | |
context = {} | |
return render(request, 'invoice/index.html', context) | |
@anonymous_required | |
def login(request): | |
#Rest of login function goes here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment