本文整理汇总了Python中django.views.defaults.permission_denied方法的典型用法代码示例。如果您正苦于以下问题:Python defaults.permission_denied方法的具体用法?Python defaults.permission_denied怎么用?Python defaults.permission_denied使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.views.defaults
的用法示例。
在下文中一共展示了defaults.permission_denied方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: custom_permission_denied_view
# 需要导入模块: from django.views import defaults [as 别名]
# 或者: from django.views.defaults import permission_denied [as 别名]
def custom_permission_denied_view(request, exception, template_name=ERROR_403_TEMPLATE_NAME):
"""
The Permission Denied view normally lacks information about the view that triggered the
exception, unless this information was provided in the exception object manually (as the
second parameter). This custom view attempts to include the relevant information if it
is available.
It is used, among others, by the Auth mixin to provide data about the offending view to
the Debug toolbar.
"""
response = permission_denied(request, exception.args[0] if exception.args else exception, template_name)
try:
response.context_data = getattr(response, 'context_data', {})
response.context_data['view'] = exception.args[1]
except IndexError:
pass
return response
示例2: debug_permission_denied
# 需要导入模块: from django.views import defaults [as 别名]
# 或者: from django.views.defaults import permission_denied [as 别名]
def debug_permission_denied(request):
return defaults.permission_denied(request, AttributeError('foobar'))
示例3: forbidden
# 需要导入模块: from django.views import defaults [as 别名]
# 或者: from django.views.defaults import permission_denied [as 别名]
def forbidden(request):
"""
Custom 403 handler.
"""
if request.path.startswith('/api/'):
return HttpResponseForbidden('You do not have permission to access this resource',
content_type='application/json')
return defaults.permission_denied(request)