我试图使用通配符技术在URL中为请求实现权限判断机制,而不是在每个视图上实现权限判断.
目前我拥有的是.
urlpatterns = [
path('admin/', include('admin_urls.py')),
...
]
我的admin_urls.py
分如下
urlpatterns = [
path('', ViewSpaceIndex.as_view(), name="admin_index"),
path('', EmployeeView.as_view(), name="employee"),
...
]
观点如下
@method_decorator(admin_required, name='dispatch')
class EmployeeView(TemplateView):
template_name = 'secret.html'
@method_decorator(admin_required, name='dispatch')
class EmployeeView(TemplateView):
template_name = 'secret.html'
我想要实现的是,不必在每个视图中重复使用@method_decorator(admin_required, name='dispatch')
decorator,我想将许可应用于一个野生动物
http.authorizeRequests()
.antMatchers("/admin/**").has_permission("is_admin")