Skip to content

Instantly share code, notes, and snippets.

@skolo-online
Created August 17, 2021 07:47
Show Gist options
  • Save skolo-online/11edb3506eb8a1ef51d024c79650f1c4 to your computer and use it in GitHub Desktop.
Save skolo-online/11edb3506eb8a1ef51d024c79650f1c4 to your computer and use it in GitHub Desktop.
Python Django invoicing app - views and decorators
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