[1.6.x] Fixed #20667 - Removed discussion of DEBUG from tutorial.

Backport of 0d642aac86 from master.
This commit is contained in:
Tim Graham 2013-06-30 14:48:15 -04:00
parent 02976a46c9
commit 3493f18d78
4 changed files with 27 additions and 52 deletions

View file

@ -454,51 +454,6 @@ just as :func:`~django.shortcuts.get_object_or_404` -- except using
:meth:`~django.db.models.query.QuerySet.get`. It raises
:exc:`~django.http.Http404` if 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`` 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. If you don't set
``handler404``, the built-in view :func:`django.views.defaults.page_not_found`
is used by default. Optionally, you can create a ``404.html`` template
in the root of your template directory. The default 404 view will then use that
template for all 404 errors when :setting:`DEBUG` is set to ``False`` (in your
settings module). If you do create the template, add at least some dummy
content like "Page not found".
.. warning::
If :setting:`DEBUG` is set to ``False``, all responses will be
"Bad Request (400)" unless you specify the proper :setting:`ALLOWED_HOSTS`
as well (something like ``['localhost', '127.0.0.1']`` for
local development).
A couple more things to note about 404 views:
* If :setting:`DEBUG` is set to ``True`` (in your settings module) then your
404 view will never be used (and thus the ``404.html`` template will never
be rendered) because the traceback will be displayed instead.
* The 404 view is also called if Django doesn't find a match after checking
every regular expression in the URLconf.
Write a 500 (server error) view
===============================
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.
Likewise, you should create a ``500.html`` template at the root of your
template directory and add some content like "Something went wrong".
Use the template system
=======================