defaults.page_not_found(request, exception, 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 two variables to the template: request_path
, which is the URL that resulted in the error, and exception
, which is a useful representation of the exception that triggered the view (e.g. containing any message passed to a specific Http404
instance).
Three things to note about 404 views:
- The 404 view is also called if Django doesn’t find a match after checking every regular expression in the URLconf.
- The 404 view is passed a
RequestContext
and will have access to variables supplied by your template context processors (e.g.MEDIA_URL
). - If
DEBUG
is set toTrue
(in your settings module), then your 404 view will never be used, and your URLconf will be displayed instead, with some debug information.
The signature of page_not_found()
changed. The function now accepts a second parameter, the exception that triggered the error. A useful representation of the exception is also passed in the template context.
Passing a nonexistent template_name
will raise TemplateDoesNotExist
.
Please login to continue.