本文整理匯總了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