Ticket #16214: clean-up-error-views-docs.patch
File clean-up-error-views-docs.patch, 4.5 KB (added by , 13 years ago) |
---|
-
docs/topics/http/views.txt
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 Th is``page_not_found`` view should suffice for 99% of Web applications, but if140 you want to override the 404 view, you can specify ``handler404`` in your141 URLconf, likeso::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: 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. 155 159 156 * The 404 view is also called if Django doesn't find a match after checking157 every regular expression in the URLconf.158 159 * If you don't define your own 404 view -- and simply use the160 default, which is recommended -- you still have one obligation:161 you must create a ``404.html`` template in the root of your162 template directory. The default 404 view will use that template163 for all 404 errors. The default 404 view will pass one variable164 to the template: ``request_path``, which is the URL that resulted165 in the 404.166 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 tracebackwill be displayed174 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 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.