liveBook · Manning

HTTP 404 error

As explained in Django in Action

HTTP 404 Not Found is an HTTP response status indicating that the requested resource could not be found.

An HTTP 404 Not Found response tells the browser that the requested resource could not be found. In Django, a missing database object can become a 404 page instead of a crash or an empty result. section 4.6.1 section 8.4

A common detail-view flow captures an integer from the URL, passes it to get_object_or_404(), and renders the object when found. If the lookup finds nothing—or does not identify one object—the shortcut raises Http404; Django catches it and returns the 404 response. section 4.6.1

A missing musician

The route /bands/musician/100/ passes 100 as musician_id. If no Musician has that ID, the detail page is replaced by a 404 page. A real URL is public input, so the view must handle typed or otherwise invalid arguments rather than trusting links to be correct. section 4.6.1

How Django in Action covers it

How deep it goes
Explains lookup, exception conversion, response handling, customization, and status-code testing, but not HTTP protocol internals.
Examples
Uses musician IDs, the Steve Vai detail page, nonexistent ID 100, and a test request for nonexistent ID 10.
What it assumes
Assumes basic Django views, URL patterns, models, templates, and Python tests while explaining invalid URL arguments from the ground up.
What you can do after
Diagnose missing-resource behavior and test it by asserting that a Django client response has status code 404.
How it connects
Connects URL patterns, URL arguments, Django views, database lookups, Http404, templates, and automated testing.

Also explained in

Compare how 3 books explain HTTP 404 error →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Django in Action. The section links point to the parts of the book it draws on.