[SOLVED] In Django how to add login required for entire app? – Stack Overflow

Issue

This Content is from Stack Overflow. Question asked by Manoj Kamble

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?



Solution

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


This Question was asked in StackOverflow by Manoj Kamble and Answered by ilyasbbu It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?