我如何在django中使整个urlconf需要登录

时间:2018-08-26 10:44:50

标签: python django

我在根url conf中有以下代码

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

为了使网址登录受到保护,我必须转到frontend->urls.py并为每个路径添加以下代码( login_required 装饰器)

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

这是很乏味的,我们也可能会忘记。所以我的问题是如何为urlconf组启用login_required保护?有什么办法可以从根urlconf启用它?像下面吗?

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

以便整个集合都受到保护!!

NB :我在Best way to make Django's login_required the default这里读到了这个答案,

仍然,这需要在其他地方指定网址,

Django 2.1Python 3.6

0 个答案:

没有答案