Beispiel #1
0
def page_not_found(request, exception):
    try:
        locale = get_language_from_request(request)
    except:
        locale = "en"
    with language(
            locale):  # Middleware might not have run, need to do this manually
        exception_repr = exception.__class__.__name__
        # Try to get an "interesting" exception message, if any (and not the ugly
        # Resolver404 dictionary)
        try:
            message = exception.args[0]
        except (AttributeError, IndexError):
            pass
        else:
            if isinstance(message, (str, Promise)):
                exception_repr = str(message)
        context = {
            'request_path': request.path,
            'exception': exception_repr,
        }
        template = get_template('404.html')
        body = template.render(context, request)
        r = HttpResponseNotFound(body)
        r.xframe_options_exempt = True
        return r
Beispiel #2
0
def page_not_found(request, exception):
    exception_repr = exception.__class__.__name__
    # Try to get an "interesting" exception message, if any (and not the ugly
    # Resolver404 dictionary)
    try:
        message = exception.args[0]
    except (AttributeError, IndexError):
        pass
    else:
        if isinstance(message, (str, Promise)):
            exception_repr = str(message)
    context = {
        'request_path': request.path,
        'exception': exception_repr,
    }
    template = get_template('404.html')
    body = template.render(context, request)
    r = HttpResponseNotFound(body)
    r.xframe_options_exempt = True
    return r
Beispiel #3
0
def page_not_found(request, exception):
    exception_repr = exception.__class__.__name__
    # Try to get an "interesting" exception message, if any (and not the ugly
    # Resolver404 dictionary)
    try:
        message = exception.args[0]
    except (AttributeError, IndexError):
        pass
    else:
        if isinstance(message, str) or isinstance(message, Promise):
            exception_repr = str(message)
    context = {
        'request_path': request.path,
        'exception': exception_repr,
    }
    template = get_template('404.html')
    body = template.render(context, request)
    r = HttpResponseNotFound(body)
    r.xframe_options_exempt = True
    return r