Most of the times many people will frequently come across the same error page that is 404 error page . Actually the 404 error is a standard HTTP error message code that is raised when there is a client-side errors like passing incorrect URL or poor internet connection and server-side mistakes like the URL called upon doesn’t exist or has not been defined or if the server is down and other things that will lead to 404 error page is because of broken links or the page has been moved to different address that indirectly convey that the server cannot find the required URL customization of 404 error page .

Most of the 404 error page are not given high priority but that 404 error page are the effective tools customized in such a manner that the user should get impress and this will be a effective tool for conveying your brand identity, entertaining visitors and keeping them on your site rather than clicking away in annoyance. Of course, you don’t actually want visitors to find themselves there at all but adding some personality and clever design can add a silver lining to an error.

The below content briefly explains about the customization of 404 error page.

customization of Django 404 error page

404 Error page
should be the most famous status code. In production, a good Django project has to handle this error with your own
custom 404 error page. I will show you how to accomplish this with simple steps.

Let’s create a Django project without losing time.

Open your console and write these lines:

$ cd Desktop
$ mkdir 404_error_page .
$ cd 404_error_page .

Then create a Django project:

                  django-admin startproject error_page_404 .

Using below line we run server

                 python runserver

If you visit you will see the Django welcome page

Django Welcome Page

Let’s try to go to a non-existing page on our website. For example, I will go to
<a href="<random_value>.

Default Not Found Page

You’re seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

Let’s do that by turning off Django debug mode. For this, we need to update the      file

   Debug = False

Note: In production, you need to change ALLOWED_HOSTS to ‘’

Refresh the page :

Use this command and create a file under the mysite folder

               touch error_page_404/

I know it is weird to have a file under the project directory. We are always
told that is a file that is under each app directory, not the project itself. But
this is the suggested way in the official document.

Your Django project should look like this:

├── db.sqlite3
└── error_page_404
  ├── init .py
  ├── pycache
  └── wsgi.p

Now we will add a function that handles 404 error by putting these lines to the
mysite/ file:

from django.shortcuts import render

def error_404_view(request, exception):
return render(request, '404_error_page.html', status=404)

Don’t forget to add this function to the bottom of mysite/ file

In the end, mysite/ file becomes

from django.contrib import admin
from django.urls import path

urlpatterns = [
handler404 = "error_page_404.views.error_404_view"

First, we need to create a templates folder and then we will add a 404.html file to this

$ mkdir templates
$ touch templates/404_error_page.html

You need to tell Django where your templates folder is located so update the file.

import os

'DIRS': [os.path.join(BASE_DIR, 'templates')],

In 404_error_page.html you are now able to customize the error message page as you desire. I am
keeping it simple:

<h1>404 Page Not Found</h1>
<p>My Custom 404 Page Not Found!</p>

Before refreshing the page, be sure that your project structure should be like this:

├── error_page_404
│   ├── init .py
│   ├── pycache
│   ├──
│   ├──
│   ├──
│   ├──
│   └──
└── templates
    └── 404_error_page.html

Now you can go to any page that does not exist on your website. The 404.html
template will handle all of them.

Customized 404 Not Found Page

Voila! Our custom 404 Page Not Found is visible for any non-existing page on your

Thank You

Github link —