Python django.views.defaults.permission_denied() Examples

The following are 3 code examples of django.views.defaults.permission_denied(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.views.defaults , or try the search function .
Example #1
Source File: views.py    From pasportaservo with GNU Affero General Public License v3.0 6 votes vote down vote up
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 
Example #2
Source File: urls.py    From edx-analytics-dashboard with GNU Affero General Public License v3.0 5 votes vote down vote up
def debug_permission_denied(request):
    return defaults.permission_denied(request, AttributeError('foobar')) 
Example #3
Source File: views.py    From esdc-ce with Apache License 2.0 5 votes vote down vote up
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)