3

I have the following code in root url conf

path('dashboard/', include('frontend.urls')),

so inorder to make a url login protected I have to go to the frontend->urls.py and add the following code (the login_required decorator) for each of the paths

 path('lists', login_required(EmailListView.as_view(),login_url='/login'), name="list"),

which is quiet tedious, and we might forget as well. So my question is how can I enable login_required protection for a urlconf group? is there any way I can enable it from the root urlconf? like below?

path('dashboard/', login_required(include('frontend.urls'))), 
#something like this?
#for now I am not able to access any urls if I do this

so that the entire set is protected !!,

NB: I read this answer here Best way to make Django's login_required the default,

still, this requires specification of urls in some other place,

Django 2.1, Python 3.6

Shobi
  • 10,374
  • 6
  • 46
  • 82

1 Answers1

0

Django 4.2.4 still can't find anyway to do it. Workaround for me is :

from django.contrib.auth.mixins import LoginRequiredMixin

class MyListView(LoginRequiredMixin, View):
    ....
C.K.
  • 4,348
  • 29
  • 43