1

I am trying to handle a 404 http response error on the site. I want my 404.html content to be displayed, but for some reason when I run my local host I do get the response displayed, but my site doesn't look the same as in my contents aren't being displayed as they should. I don't know why this is happening, but I want to make sure I am properly calling in my handler. Any suggestions would be appreciated.

My views.py

def handler404(request, exception):
    return render(request, 'webpage/404.html')

My 404.html

{% extends "webpage/base.html" %}

{% block content %}
{% load static %}

<h1>404 Error</h1>

{% endblock %}

My Url.py

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('webpage.urls')),
    
]

handler404 = views.handler404
6
  • 1
    what is your DEBUG flag? docs.djangoproject.com/en/3.1/ref/views/… Commented Oct 9, 2020 at 16:55
  • I am currently on my local host so I have it set to False Commented Oct 9, 2020 at 16:58
  • what do you see instead of 404.html? Commented Oct 9, 2020 at 17:05
  • see stackoverflow.com/questions/17662928/… does it help you? Commented Oct 9, 2020 at 17:07
  • I do see my 404.html content being displayed. However, my whole site has become white and the overall style of the site has disappeared. Seems like it is not calling in my base.html where it calls in bootstrap and my other features implemented. Commented Oct 9, 2020 at 17:08

1 Answer 1

1

Here is the ref to handle the custom error page: https://docs.djangoproject.com/en/3.0/topics/http/views/#customizing-error-views

In the main py: handler404 = 'app_name.views.handler404'

In the views add :

def handler404(request, exception):
    return render(request, "webpage/404.html", {})
Sign up to request clarification or add additional context in comments.

1 Comment

Would you have any idea why I am getting a whitenoise user warning. I am getting a no directory at my staticfiles?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.