Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #16214 -- Enhanced documentation about HTTP 404 and 500 status …

…views and templates. Thanks Aymeric Augustin for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16449 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a3117699a5a06ed6c488c96738c335b5b5f065c0 1 parent d257ab4
Ramiro Morales authored June 25, 2011

Showing 1 changed file with 31 additions and 34 deletions. Show diff stats Hide diff stats

  1. 65  docs/topics/http/views.txt
65  docs/topics/http/views.txt
@@ -134,44 +134,36 @@ to handling 404 errors. By default, it's the view
134 134
 ``404.html``.
135 135
 
136 136
 This means you need to define a ``404.html`` template in your root template
137  
-directory. This template will be used for all 404 errors.
  137
+directory. This template will be used for all 404 errors. The default 404 view
  138
+will pass one variable to the template: ``request_path``, which is the URL
  139
+that resulted in the error.
138 140
 
139  
-This ``page_not_found`` view should suffice for 99% of Web applications, but if
140  
-you want to override the 404 view, you can specify ``handler404`` in your
141  
-URLconf, like so::
  141
+The ``page_not_found`` view should suffice for 99% of Web applications, but if
  142
+you want to override it, you can specify ``handler404`` in your URLconf, like
  143
+so::
142 144
 
143 145
     handler404 = 'mysite.views.my_custom_404_view'
144 146
 
145  
-Behind the scenes, Django determines the 404 view by looking for ``handler404``.
146  
-By default, URLconfs contain the following line::
  147
+Behind the scenes, Django determines the 404 view by looking for
  148
+``handler404`` in your root URLconf, and falling back to
  149
+``django.views.defaults.page_not_found`` if you did not define one.
147 150
 
148  
-    from django.conf.urls.defaults import *
  151
+Four things to note about 404 views:
149 152
 
150  
-That takes care of setting ``handler404`` in the current module. As you can see
151  
-in ``django/conf/urls/defaults.py``, ``handler404`` is set to
152  
-``'django.views.defaults.page_not_found'`` by default.
  153
+    * The 404 view is also called if Django doesn't find a match after
  154
+      checking every regular expression in the URLconf.
153 155
 
154  
-Three things to note about 404 views:
155  
-
156  
-    * The 404 view is also called if Django doesn't find a match after checking
157  
-      every regular expression in the URLconf.
158  
-
159  
-    * If you don't define your own 404 view -- and simply use the
160  
-      default, which is recommended -- you still have one obligation:
161  
-      you must create a ``404.html`` template in the root of your
162  
-      template directory. The default 404 view will use that template
163  
-      for all 404 errors. The default 404 view will pass one variable
164  
-      to the template: ``request_path``, which is the URL that resulted
165  
-      in the 404.
  156
+    * If you don't define your own 404 view — and simply use the default,
  157
+      which is recommended — you still have one obligation: you must create a
  158
+      ``404.html`` template in the root of your template directory.
166 159
 
167 160
     * The 404 view is passed a :class:`~django.template.RequestContext` and
168 161
       will have access to variables supplied by your
169  
-      :setting:`TEMPLATE_CONTEXT_PROCESSORS` setting (e.g.,
170  
-      :setting:`MEDIA_URL`).
  162
+      :setting:`TEMPLATE_CONTEXT_PROCESSORS` setting (e.g., ``MEDIA_URL``).
171 163
 
172 164
     * If :setting:`DEBUG` is set to ``True`` (in your settings module), then
173  
-      your 404 view will never be used, and the traceback will be displayed
174  
-      instead.
  165
+      your 404 view will never be used, and your URLconf will be displayed
  166
+      instead, with some debug information.
175 167
 
176 168
 The 500 (server error) view
177 169
 ----------------------------
@@ -187,16 +179,21 @@ view passes no variables to this template and is rendered with an empty
187 179
 ``Context`` to lessen the chance of additional errors.
188 180
 
189 181
 This ``server_error`` view should suffice for 99% of Web applications, but if
190  
-you want to override the view, you can specify ``handler500`` in your
191  
-URLconf, like so::
  182
+you want to override the view, you can specify ``handler500`` in your URLconf,
  183
+like so::
192 184
 
193 185
     handler500 = 'mysite.views.my_custom_error_view'
194 186
 
195  
-Behind the scenes, Django determines the error view by looking for ``handler500``.
196  
-By default, URLconfs contain the following line::
  187
+Behind the scenes, Django determines the 500 view by looking for
  188
+``handler500`` in your root URLconf, and falling back to
  189
+``django.views.defaults.server_error`` if you did not define one.
197 190
 
198  
-    from django.conf.urls.defaults import *
  191
+Two things to note about 500 views:
199 192
 
200  
-That takes care of setting ``handler500`` in the current module. As you can see
201  
-in ``django/conf/urls/defaults.py``, ``handler500`` is set to
202  
-``'django.views.defaults.server_error'`` by default.
  193
+    * If you don't define your own 500 view — and simply use the default,
  194
+      which is recommended — you still have one obligation: you must create a
  195
+      ``500.html`` template in the root of your template directory.
  196
+
  197
+    * If :setting:`DEBUG` is set to ``True`` (in your settings module), then
  198
+      your 500 view will never be used, and the traceback will be displayed
  199
+      instead, with some debug information.

0 notes on commit a311769

Please sign in to comment.
Something went wrong with that request. Please try again.