25 lines
804 B
Python
25 lines
804 B
Python
from django.shortcuts import redirect
|
|
from django.conf import settings
|
|
from django.urls import reverse
|
|
|
|
EXEMPT_URLS = [
|
|
# reverse('login'), # or the name of your login view
|
|
reverse('admin:login'),
|
|
reverse('admin:index'),
|
|
# reverse('logout'), # optional
|
|
'/admin/', # allow full access to admin
|
|
settings.STATIC_URL, # allow static files
|
|
# path('scheduler/', include('scheduler.urls')),
|
|
]
|
|
|
|
class LoginRequiredMiddleware:
|
|
def __init__(self, get_response):
|
|
self.get_response = get_response
|
|
|
|
def __call__(self, request):
|
|
if not request.user.is_authenticated:
|
|
path = request.path
|
|
if not any(path.startswith(url) for url in EXEMPT_URLS):
|
|
return redirect(settings.LOGIN_URL)
|
|
return self.get_response(request)
|