From 94524fbfef09bf18422141a2c8c73e880aa25b14 Mon Sep 17 00:00:00 2001 From: James Bennett Date: Sun, 11 Sep 2011 04:01:41 +0000 Subject: [PATCH] Fixed #16079: Clarified (for real this time) how handler404 and handler500 work, and that they only work in a root URLconf. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16804 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/intro/tutorial03.txt | 18 ++++++++-------- docs/topics/http/urls.txt | 42 ++++++++++++++++++++++++++------------ docs/topics/http/views.txt | 2 ++ 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/docs/intro/tutorial03.txt b/docs/intro/tutorial03.txt index c6071477510..82cf60b1181 100644 --- a/docs/intro/tutorial03.txt +++ b/docs/intro/tutorial03.txt @@ -356,11 +356,13 @@ the list is empty. Write a 404 (page not found) view ================================= -When you raise :exc:`~django.http.Http404` from within a view, Django will load -a special view devoted to handling 404 errors. It finds it by looking for the -variable ``handler404``, which is a string in Python dotted syntax -- the same -format the normal URLconf callbacks use. A 404 view itself has nothing special: -It's just a normal view. +When you raise :exc:`~django.http.Http404` from within a view, Django +will load a special view devoted to handling 404 errors. It finds it +by looking for the variable ``handler404`` in your root URLconf (and +only in your root URLconf; setting ``handler404`` anywhere else will +have no effect), which is a string in Python dotted syntax -- the same +format the normal URLconf callbacks use. A 404 view itself has nothing +special: It's just a normal view. You normally won't have to bother with writing 404 views. By default, URLconfs have the following line up top:: @@ -392,9 +394,9 @@ Four more things to note about 404 views: Write a 500 (server error) view =============================== -Similarly, URLconfs may define a ``handler500``, which points to a view to call -in case of server errors. Server errors happen when you have runtime errors in -view code. +Similarly, your root URLconf may define a ``handler500``, which points +to a view to call in case of server errors. Server errors happen when +you have runtime errors in view code. Use the template system ======================= diff --git a/docs/topics/http/urls.txt b/docs/topics/http/urls.txt index 9b6e2d07492..7b87ad37522 100644 --- a/docs/topics/http/urls.txt +++ b/docs/topics/http/urls.txt @@ -60,6 +60,10 @@ algorithm the system follows to determine which Python code to execute: :class:`~django.http.HttpRequest` as its first argument and any values captured in the regex as remaining arguments. + 5. If no regex matches, or if an exception is raised during any + point in this process, Django invokes an appropriate + error-handling view. See `Error handling`_ below. + Example ======= @@ -252,6 +256,31 @@ The ``prefix`` parameter has the same meaning as the first argument to ``patterns()`` and is only relevant when you're passing a string as the ``view`` parameter. +include +------- + +.. function:: include() + +A function that takes a full Python import path to another URLconf module that +should be "included" in this place. + +:func:`include` also accepts as an argument an iterable that returns URL +patterns. + +See `Including other URLconfs`_ below. + +Error handling +============== + +When Django can't find a regex matching the requested URL, or when an +exception is raised, Django will invoke an error-handling view. The +views to use for these cases are specified by two variables which can +be set in your root URLconf. Setting these variables in any other +URLconf will have no effect. + +See the documentation on :ref:`customizing error views +` for more details. + handler404 ---------- @@ -281,19 +310,6 @@ value should suffice. .. versionchanged:: 1.2 Previous versions of Django only accepted strings representing import paths. -include -------- - -.. function:: include() - -A function that takes a full Python import path to another URLconf module that -should be "included" in this place. - -:func:`include` also accepts as an argument an iterable that returns URL -patterns. - -See `Including other URLconfs`_ below. - Notes on capturing text in URLs =============================== diff --git a/docs/topics/http/views.txt b/docs/topics/http/views.txt index d4603615b06..247669d9ea7 100644 --- a/docs/topics/http/views.txt +++ b/docs/topics/http/views.txt @@ -122,6 +122,8 @@ In order to use the ``Http404`` exception to its fullest, you should create a template that is displayed when a 404 error is raised. This template should be called ``404.html`` and located in the top level of your template tree. +.. _customizing-error-views: + Customizing error views =======================