Solution 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", {})

Problem :

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

Comments

Comment posted by docs.djangoproject.com/en/3.1/ref/views/…

what is your

Comment posted by anon

I am currently on my local host so I have it set to False

Comment posted by Paweł Kordowski

what do you see instead of 404.html?

Comment posted by stackoverflow.com/questions/17662928/…

see

Comment posted by anon

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.

Comment posted by anon

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

By