Hi, hope you are doing well
i’m currently building a very small SAAS (School Management System) which is a panel where all urls are restricted to only logged In users so i decided to use the new LoginRequiredMiddleware
.
but there is some urls like the login url which is public but there is also some public apps that doesn’t need a restriction like the subscription, landing static pages blog …etc
i didn’t want to decorate all this views so i did this
from django.contrib.auth.middleware import LoginRequiredMiddleware as DjangoLoginRequiredMiddleware
LOGIN_NOT_REQUIRED_APPS = ['landing', 'subscription']
class LoginRequiredMiddleware(DjangoLoginRequiredMiddleware):
def process_view(self, request, view_func, view_args, view_kwargs):
match = request.resolver_match # this was added
if request.user.is_authenticated:
return None
if match.app_name in LOGIN_NOT_REQUIRED_APPS: # this was added
return None
if not getattr(view_func, "login_required", True):
return None
return self.handle_no_permission(request, view_func)
my question is why it is not built in the Middleware by default, i’m i missing something ?
thank you by advance for your time and responses.