Files
matitos_news/app_urls/fetcher/middleware/login_required.py

23 lines
709 B
Python

from django.shortcuts import redirect
from django.conf import settings
from django.urls import reverse
EXEMPT_URLS = [
reverse('admin:login'),
reverse('admin:index'),
'/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)