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
anon
  • 75
  • 8

1 Answers1

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", {})
Subasri sridhar
  • 809
  • 5
  • 13
  • Would you have any idea why I am getting a whitenoise user warning. I am getting a no directory at my staticfiles? – anon Oct 09 '20 at 17:13