def handle_permission_denied_exception(request, exception): try: error_message = exception.args[0] except IndexError: error_message = None return errorpages.permission_denied(request, error_message)