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