The 404 Page
Part of the Django Basics section of Coddy's Django journey. Lesson 5 of 23.
Someone added a Contact page, but it shows Page not found. 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 responds with 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
EasyThe Contact page shows Page not found. Read the patterns Django tried on that page, then fix the route in menu/urls.py.
Open /contact/: it 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),
]
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