當前位置: 首頁>>代碼示例>>Python>>正文


Python decorators.permission_required方法代碼示例

本文整理匯總了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')) 
開發者ID:ilavender,項目名稱:sensu_drive,代碼行數:12,代碼來源:views.py

示例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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:11,代碼來源:test_decorators.py

示例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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:11,代碼來源:test_decorators.py

示例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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:11,代碼來源:test_decorators.py

示例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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:11,代碼來源:test_decorators.py

示例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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:13,代碼來源:test_decorators.py

示例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 
開發者ID:5monkeys,項目名稱:django-bananas,代碼行數:14,代碼來源:extension.py


注:本文中的django.contrib.auth.decorators.permission_required方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。