Adding a custom 404 page is a best practice for any Django website. This post shows a quick tip for how to test and configure a custom 404 page in your Django projects.

Create a new Django project.

$ cd Desktop
$ mkdir demo && cd demo
$ pipenv install django
$ pipenv shell
(demo) $ django-admin startproject demo_project .
(demo) $ python runserver

The Django welcome page is visible at

Django welcome page

Now go to any other page which should result in a 404. For example

No 404 page

If we change DEBUG to False and add our localhost to the ALLOWED_HOSTS setting then we can see the built-in 404 page which can then be customized. ALLOWED_HOSTS restricts which HTTP requests Django will respond to so the URL needs to be explicitly added.

# demo_project/
DEBUG = False


Refresh the page again at

Django default 404

Now let’s update it with custom text. First create a templates folder and then add a 404.html file to it.

(demo) $ mkdir templates
(demo) $ touch templates/404.html

Update so Django will look for this new templates folder.

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

And finally add some basic text to the file.

<!-- templates/404.html -->
<h1>404 Page Not Found</h1>
<p>This page does not exist yet!</p>

Now refresh the page once more to see our work.

Django custom 404 page

Looking for a way to go from beginner to intermediate Django developer? Check out my book Django for Beginners.