Ticket #16214: clean-up-error-views-docs.patch

File clean-up-error-views-docs.patch, 4.5 KB (added by Aymeric Augustin, 13 years ago)
  • docs/topics/http/views.txt

     
    134134``404.html``.
    135135
    136136This means you need to define a ``404.html`` template in your root template
    137 directory. This template will be used for all 404 errors.
     137directory. This template will be used for all 404 errors. The default 404 view
     138will pass one variable to the template: ``request_path``, which is the URL
     139that resulted in the error.
    138140
    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::
     141The ``page_not_found`` view should suffice for 99% of Web applications, but if
     142you want to override it, you can specify ``handler404`` in your URLconf, like
     143so::
    142144
    143145    handler404 = 'mysite.views.my_custom_404_view'
    144146
    145 Behind the scenes, Django determines the 404 view by looking for ``handler404``.
    146 By default, URLconfs contain the following line::
     147Behind 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.
    147150
    148     from django.conf.urls.defaults import *
     151Four things to note about 404 views:
    149152
    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.
    153155
    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.
    155159
    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.
    166 
    167160    * The 404 view is passed a :class:`~django.template.RequestContext` and
    168161      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``).
    171163
    172164    * 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.
    175167
    176168The 500 (server error) view
    177169----------------------------
     
    187179``Context`` to lessen the chance of additional errors.
    188180
    189181This ``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::
     182you want to override the view, you can specify ``handler500`` in your URLconf,
     183like so::
    192184
    193185    handler500 = 'mysite.views.my_custom_error_view'
    194186
    195 Behind the scenes, Django determines the error view by looking for ``handler500``.
    196 By default, URLconfs contain the following line::
     187Behind 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.
    197190
    198     from django.conf.urls.defaults import *
     191Two things to note about 500 views:
    199192
    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.
Back to Top