Menu
CoddyTech

The 404 Page

Part of the Django Basics section of Coddy's Django journey. Lesson 5 of 23.

Someone added a Contact page, and it answers 404. The view is fine.

404 is a status code, a number the server sends with every response: 200 means OK, 404 means no such page. Django answers 404 when no route matches.

With DEBUG = True in settings.py, the 404 page is written for you, the developer: it lists every pattern Django tried and the path it got. On another site it might read:

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

    menu/
    events/
    galery/

The current path, gallery/, didn't match any of these.

Read the path against each pattern, letter by letter. Routes match exactly: gallery/ is not galery/, and not Gallery/. A live site sets DEBUG = False, so visitors never see this list.

challenge icon

Challenge

Easy

Open /contact/ in the preview, read the patterns Django tried, and fix the route in menu/urls.py.

Press Run: /contact/ says Write to us at hello@cornercafe.example.

Try it yourself

from django.urls import path

from . import views

urlpatterns = [
    path("", views.home),
    path("about/", views.about),
    path("hours/", views.hours),
    path("contcat/", views.contact),
]
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Django Basics

Practice on your own: Django playground