当前位置: 首页>>代码示例>>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;未经允许,请勿转载。