PageRenderTime 19ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

Plain Text | 95 lines | 68 code | 27 blank | 0 comment | 0 complexity | 386d2a697b57a6e98a4b76c9a65d879d MD5 | raw file
Possible License(s): BSD-3-Clause
  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 e-mail 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 e-mail from root@localhost. However, some mail
  29. providers reject all e-mail 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. .. seealso::
  34. .. versionadded:: 1.3
  35. Server error e-mails are sent using the logging framework, so you can
  36. customize this behaviour by :doc:`customizing your logging configuration
  37. </topics/logging>`.
  38. 404 errors
  39. ----------
  40. Django can also be configured to e-mail errors about broken links (404 "page
  41. not found" errors). Django sends e-mails about 404 errors when:
  42. * :setting:`DEBUG` is ``False``
  43. * :setting:`SEND_BROKEN_LINK_EMAILS` is ``True``
  44. * Your :setting:`MIDDLEWARE_CLASSES` setting includes ``CommonMiddleware``
  45. (which it does by default).
  46. If those conditions are met, Django will e-mail the users listed in the
  47. :setting:`MANAGERS` setting whenever your code raises a 404 and the request has
  48. a referer. (It doesn't bother to e-mail for 404s that don't have a referer --
  49. those are usually just people typing in broken URLs or broken Web 'bots).
  50. You can tell Django to stop reporting particular 404s by tweaking the
  51. :setting:`IGNORABLE_404_ENDS` and :setting:`IGNORABLE_404_STARTS` settings. Both
  52. should be a tuple of strings. For example::
  53. IGNORABLE_404_ENDS = ('.php', '.cgi')
  54. IGNORABLE_404_STARTS = ('/phpmyadmin/',)
  55. In this example, a 404 to any URL ending with ``.php`` or ``.cgi`` will *not* be
  56. reported. Neither will any URL starting with ``/phpmyadmin/``.
  57. The best way to disable this behavior is to set
  58. :setting:`SEND_BROKEN_LINK_EMAILS` to ``False``.
  59. .. seealso::
  60. You can also set up custom error reporting by writing a custom piece of
  61. :ref:`exception middleware <exception-middleware>`. If you do write custom
  62. error handling, it's a good idea to emulate Django's built-in error handling
  63. and only report/log errors if :setting:`DEBUG` is ``False``.
  64. .. seealso::
  65. .. versionadded:: 1.3
  66. 404 errors are logged using the logging framework. By default, these log
  67. records are ignored, but you can use them for error reporting by writing a
  68. handler and :doc:`configuring logging </topics/logging>` appropriately.