本文整理汇总了Python中django.contrib.auth.decorators.permission_required方法的典型用法代码示例。如果您正苦于以下问题:Python decorators.permission_required方法的具体用法?Python decorators.permission_required怎么用?Python decorators.permission_required使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.auth.decorators
的用法示例。
在下文中一共展示了decorators.permission_required方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rules
# 需要导入模块: from django.contrib.auth import decorators [as 别名]
# 或者: from django.contrib.auth.decorators import permission_required [as 别名]
def rules(request):
mimetype = 'application/json'
data = {}
return HttpResponse(json.dumps(data), mimetype)
#@permission_required('is_staff', login_url=reverse_lazy('login'))
#@login_required(login_url=reverse_lazy('login'))
示例2: test_many_permissions_pass
# 需要导入模块: from django.contrib.auth import decorators [as 别名]
# 或者: from django.contrib.auth.decorators import permission_required [as 别名]
def test_many_permissions_pass(self):
@permission_required(['auth_tests.add_customuser', 'auth_tests.change_customuser'])
def a_view(request):
return HttpResponse()
request = self.factory.get('/rand')
request.user = self.user
resp = a_view(request)
self.assertEqual(resp.status_code, 200)
示例3: test_many_permissions_in_set_pass
# 需要导入模块: from django.contrib.auth import decorators [as 别名]
# 或者: from django.contrib.auth.decorators import permission_required [as 别名]
def test_many_permissions_in_set_pass(self):
@permission_required({'auth_tests.add_customuser', 'auth_tests.change_customuser'})
def a_view(request):
return HttpResponse()
request = self.factory.get('/rand')
request.user = self.user
resp = a_view(request)
self.assertEqual(resp.status_code, 200)
示例4: test_single_permission_pass
# 需要导入模块: from django.contrib.auth import decorators [as 别名]
# 或者: from django.contrib.auth.decorators import permission_required [as 别名]
def test_single_permission_pass(self):
@permission_required('auth_tests.add_customuser')
def a_view(request):
return HttpResponse()
request = self.factory.get('/rand')
request.user = self.user
resp = a_view(request)
self.assertEqual(resp.status_code, 200)
示例5: test_permissioned_denied_redirect
# 需要导入模块: from django.contrib.auth import decorators [as 别名]
# 或者: from django.contrib.auth.decorators import permission_required [as 别名]
def test_permissioned_denied_redirect(self):
@permission_required(['auth_tests.add_customuser', 'auth_tests.change_customuser', 'nonexistent-permission'])
def a_view(request):
return HttpResponse()
request = self.factory.get('/rand')
request.user = self.user
resp = a_view(request)
self.assertEqual(resp.status_code, 302)
示例6: test_permissioned_denied_exception_raised
# 需要导入模块: from django.contrib.auth import decorators [as 别名]
# 或者: from django.contrib.auth.decorators import permission_required [as 别名]
def test_permissioned_denied_exception_raised(self):
@permission_required([
'auth_tests.add_customuser', 'auth_tests.change_customuser', 'nonexistent-permission'
], raise_exception=True)
def a_view(request):
return HttpResponse()
request = self.factory.get('/rand')
request.user = self.user
with self.assertRaises(PermissionDenied):
a_view(request)
示例7: admin_view
# 需要导入模块: from django.contrib.auth import decorators [as 别名]
# 或者: from django.contrib.auth.decorators import permission_required [as 别名]
def admin_view(self, view, perm=None):
if perm is not None:
perm = self.get_permission(perm)
else:
perm = self.access_permission
admin_login_url = compat.reverse_lazy("admin:login")
view = user_passes_test(
lambda u: u.is_active and u.is_staff, login_url=admin_login_url
)(view)
view = permission_required(perm, login_url=admin_login_url)(view)
return view