【发布时间】:2022-08-14 17:13:34
【问题描述】:
我正在尝试使用通配符技术在请求的 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\') 装饰器在我想将权限应用于狂野的每个视图中
带有admin_required 权限的卡片URLs \'/admin/**\',如下所示。
http.authorizeRequests()
.antMatchers(\"/admin/**\").has_permission(\"is_admin\")
标签: django spring-boot django-rest-framework django-views django-permissions