Error views

Django comes with a few views by default for handling HTTP errors. To override these with your own custom views, see customizing-error-views.

The 404 (page not found) view

defaults.page_not_found(request, template_name='404.html')

When you raise Http404 from within a view, Django loads a special view devoted to handling 404 errors. By default, it's the view django.views.defaults.page_not_found(), which either produces a very simple Not Found message or loads and renders the template 404.html if you created it in your root template directory.

The default 404 view will pass one variable to the template: request_path, which is the URL that resulted in the error.

Three things to note about 404 views:

  • The 404 view is also called if Django doesn't ...

Get Mastering Django: Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.