error-reporting.txt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. Error reporting via e-mail
  2. ==========================
  3. When you're running a public site you should always turn off the
  4. :setting:`DEBUG` setting. That will make your server run much faster, and will
  5. also prevent malicious users from seeing details of your application that can be
  6. revealed by the error pages.
  7. However, running with :setting:`DEBUG` set to ``False`` means you'll never see
  8. errors generated by your site -- everyone will just see your public error pages.
  9. You need to keep track of errors that occur in deployed sites, so Django can be
  10. configured to email you details of those errors.
  11. Server errors
  12. -------------
  13. When :setting:`DEBUG` is ``False``, Django will e-mail the users listed in the
  14. :setting:`ADMINS` setting whenever your code raises an unhandled exception and
  15. results in an internal server error (HTTP status code 500). This gives the
  16. administrators immediate notification of any errors. The :setting:`ADMINS` will
  17. get a description of the error, a complete Python traceback, and details about
  18. the HTTP request that caused the error.
  19. .. note::
  20. In order to send e-mail, Django requires a few settings telling it
  21. how to connect to your mail server. At the very least, you'll need
  22. to specify :setting:`EMAIL_HOST` and possibly
  23. :setting:`EMAIL_HOST_USER` and :setting:`EMAIL_HOST_PASSWORD`,
  24. though other settings may be also required depending on your mail
  25. server's configuration. Consult :doc:`the Django settings
  26. documentation </ref/settings>` for a full list of email-related
  27. settings.
  28. By default, Django will send email from root@localhost. However, some mail
  29. providers reject all email from this address. To use a different sender
  30. address, modify the :setting:`SERVER_EMAIL` setting.
  31. To disable this behavior, just remove all entries from the :setting:`ADMINS`
  32. setting.
  33. 404 errors
  34. ----------
  35. Django can also be configured to email errors about broken links (404 "page
  36. not found" errors). Django sends emails about 404 errors when:
  37. * :setting:`DEBUG` is ``False``
  38. * :setting:`SEND_BROKEN_LINK_EMAILS` is ``True``
  39. * Your :setting:`MIDDLEWARE_CLASSES` setting includes ``CommonMiddleware``
  40. (which it does by default).
  41. If those conditions are met, Django will e-mail the users listed in the
  42. :setting:`MANAGERS` setting whenever your code raises a 404 and the request has
  43. a referer. (It doesn't bother to e-mail for 404s that don't have a referer --
  44. those are usually just people typing in broken URLs or broken web 'bots).
  45. You can tell Django to stop reporting particular 404s by tweaking the
  46. :setting:`IGNORABLE_404_ENDS` and :setting:`IGNORABLE_404_STARTS` settings. Both
  47. should be a tuple of strings. For example::
  48. IGNORABLE_404_ENDS = ('.php', '.cgi')
  49. IGNORABLE_404_STARTS = ('/phpmyadmin/',)
  50. In this example, a 404 to any URL ending with ``.php`` or ``.cgi`` will *not* be
  51. reported. Neither will any URL starting with ``/phpmyadmin/``.
  52. The best way to disable this behavior is to set
  53. :setting:`SEND_BROKEN_LINK_EMAILS` to ``False``.
  54. .. seealso::
  55. You can also set up custom error reporting by writing a custom piece of
  56. :ref:`exception middleware <exception-middleware>`. If you do write custom
  57. error handling, it's a good idea to emulate Django's built-in error handling
  58. and only report/log errors if :setting:`DEBUG` is ``False``.