1

Suppose I have 3 apps in my Django website app_1, app_2, app_3. app_1 and app_2 can access any user, but for app_3 I want the user should log in.

Using login_required I can achieve this. But I have more than 30 views and urls. I don't want to write login_required decorator on every view function. Is there any other shortcut?

Manoj Kamble
  • 620
  • 1
  • 4
  • 21
  • 6
    You can do this by introducing a middleware in your project. You will get an idea from this https://stackoverflow.com/questions/3214589/django-how-can-i-apply-the-login-required-decorator-to-my-entire-site-excludin – Ashish Nautiyal Sep 19 '22 at 05:16

1 Answers1

0

There is a pypi package called django-login-required-middelware for this purpose.

Just install it by:

pip install django-login-required-middleware

Then add login_required.middleware.LoginRequiredMiddleware to MIDDLEWARE in settinggs.py after django.contrib.auth.middleware.AuthenticationMiddleware

ilyasbbu
  • 1,468
  • 4
  • 11
  • 22