<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Error reporting via e-mail — Django v1.3.1 documentation</title> <link rel="stylesheet" href="../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '1.3.1', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <link rel="top" title="Django v1.3.1 documentation" href="../index.html" /> <link rel="up" title="“How-to” guides" href="index.html" /> <link rel="next" title="Providing initial data for models" href="initial-data.html" /> <link rel="prev" title="How to use Django with Apache and mod_python" href="deployment/modpython.html" /> <script type="text/javascript" src="../templatebuiltins.js"></script> <script type="text/javascript"> (function($) { if (!django_template_builtins) { // templatebuiltins.js missing, do nothing. return; } $(document).ready(function() { // Hyperlink Django template tags and filters var base = "../ref/templates/builtins.html"; if (base == "#") { // Special case for builtins.html itself base = ""; } // Tags are keywords, class '.k' $("div.highlight\\-html\\+django span.k").each(function(i, elem) { var tagname = $(elem).text(); if ($.inArray(tagname, django_template_builtins.ttags) != -1) { var fragment = tagname.replace(/_/, '-'); $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>"); } }); // Filters are functions, class '.nf' $("div.highlight\\-html\\+django span.nf").each(function(i, elem) { var filtername = $(elem).text(); if ($.inArray(filtername, django_template_builtins.tfilters) != -1) { var fragment = filtername.replace(/_/, '-'); $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>"); } }); }); })(jQuery); </script> </head> <body> <div class="document"> <div id="custom-doc" class="yui-t6"> <div id="hd"> <h1><a href="../index.html">Django v1.3.1 documentation</a></h1> <div id="global-nav"> <a title="Home page" href="../index.html">Home</a> | <a title="Table of contents" href="../contents.html">Table of contents</a> | <a title="Global index" href="../genindex.html">Index</a> | <a title="Module index" href="../py-modindex.html">Modules</a> </div> <div class="nav"> « <a href="deployment/modpython.html" title="How to use Django with Apache and mod_python">previous</a> | <a href="index.html" title="&#8220;How-to&#8221; guides" accesskey="U">up</a> | <a href="initial-data.html" title="Providing initial data for models">next</a> »</div> </div> <div id="bd"> <div id="yui-main"> <div class="yui-b"> <div class="yui-g" id="howto-error-reporting"> <div class="section" id="s-error-reporting-via-e-mail"> <span id="error-reporting-via-e-mail"></span><h1>Error reporting via e-mail<a class="headerlink" href="#error-reporting-via-e-mail" title="Permalink to this headline">¶</a></h1> <p>When you’re running a public site you should always turn off the <a class="reference internal" href="../ref/settings.html#std:setting-DEBUG"><tt class="xref std std-setting docutils literal"><span class="pre">DEBUG</span></tt></a> setting. That will make your server run much faster, and will also prevent malicious users from seeing details of your application that can be revealed by the error pages.</p> <p>However, running with <a class="reference internal" href="../ref/settings.html#std:setting-DEBUG"><tt class="xref std std-setting docutils literal"><span class="pre">DEBUG</span></tt></a> set to <tt class="xref docutils literal"><span class="pre">False</span></tt> means you’ll never see errors generated by your site – everyone will just see your public error pages. You need to keep track of errors that occur in deployed sites, so Django can be configured to e-mail you details of those errors.</p> <div class="section" id="s-server-errors"> <span id="server-errors"></span><h2>Server errors<a class="headerlink" href="#server-errors" title="Permalink to this headline">¶</a></h2> <p>When <a class="reference internal" href="../ref/settings.html#std:setting-DEBUG"><tt class="xref std std-setting docutils literal"><span class="pre">DEBUG</span></tt></a> is <tt class="xref docutils literal"><span class="pre">False</span></tt>, Django will e-mail the users listed in the <a class="reference internal" href="../ref/settings.html#std:setting-ADMINS"><tt class="xref std std-setting docutils literal"><span class="pre">ADMINS</span></tt></a> setting whenever your code raises an unhandled exception and results in an internal server error (HTTP status code 500). This gives the administrators immediate notification of any errors. The <a class="reference internal" href="../ref/settings.html#std:setting-ADMINS"><tt class="xref std std-setting docutils literal"><span class="pre">ADMINS</span></tt></a> will get a description of the error, a complete Python traceback, and details about the HTTP request that caused the error.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">In order to send e-mail, Django requires a few settings telling it how to connect to your mail server. At the very least, you’ll need to specify <a class="reference internal" href="../ref/settings.html#std:setting-EMAIL_HOST"><tt class="xref std std-setting docutils literal"><span class="pre">EMAIL_HOST</span></tt></a> and possibly <a class="reference internal" href="../ref/settings.html#std:setting-EMAIL_HOST_USER"><tt class="xref std std-setting docutils literal"><span class="pre">EMAIL_HOST_USER</span></tt></a> and <a class="reference internal" href="../ref/settings.html#std:setting-EMAIL_HOST_PASSWORD"><tt class="xref std std-setting docutils literal"><span class="pre">EMAIL_HOST_PASSWORD</span></tt></a>, though other settings may be also required depending on your mail server’s configuration. Consult <a class="reference internal" href="../ref/settings.html"><em>the Django settings documentation</em></a> for a full list of email-related settings.</p> </div> <p>By default, Django will send e-mail from <a class="reference external" href="mailto:root%40localhost">root<span>@</span>localhost</a>. However, some mail providers reject all e-mail from this address. To use a different sender address, modify the <a class="reference internal" href="../ref/settings.html#std:setting-SERVER_EMAIL"><tt class="xref std std-setting docutils literal"><span class="pre">SERVER_EMAIL</span></tt></a> setting.</p> <p>To disable this behavior, just remove all entries from the <a class="reference internal" href="../ref/settings.html#std:setting-ADMINS"><tt class="xref std std-setting docutils literal"><span class="pre">ADMINS</span></tt></a> setting.</p> <div class="admonition-see-also admonition seealso"> <p class="first admonition-title">See also</p> <div class="versionadded"> <span class="title">New in Django 1.3:</span> <a class="reference internal" href="../releases/1.3.html"><em>Please, see the release notes</em></a></div> <p class="last">Server error e-mails are sent using the logging framework, so you can customize this behaviour by <a class="reference internal" href="../topics/logging.html"><em>customizing your logging configuration</em></a>.</p> </div> </div> <div class="section" id="s-errors"> <span id="errors"></span><h2>404 errors<a class="headerlink" href="#errors" title="Permalink to this headline">¶</a></h2> <p>Django can also be configured to e-mail errors about broken links (404 “page not found” errors). Django sends e-mails about 404 errors when:</p> <ul class="simple"> <li><a class="reference internal" href="../ref/settings.html#std:setting-DEBUG"><tt class="xref std std-setting docutils literal"><span class="pre">DEBUG</span></tt></a> is <tt class="xref docutils literal"><span class="pre">False</span></tt></li> <li><a class="reference internal" href="../ref/settings.html#std:setting-SEND_BROKEN_LINK_EMAILS"><tt class="xref std std-setting docutils literal"><span class="pre">SEND_BROKEN_LINK_EMAILS</span></tt></a> is <tt class="xref docutils literal"><span class="pre">True</span></tt></li> <li>Your <a class="reference internal" href="../ref/settings.html#std:setting-MIDDLEWARE_CLASSES"><tt class="xref std std-setting docutils literal"><span class="pre">MIDDLEWARE_CLASSES</span></tt></a> setting includes <tt class="docutils literal"><span class="pre">CommonMiddleware</span></tt> (which it does by default).</li> </ul> <p>If those conditions are met, Django will e-mail the users listed in the <a class="reference internal" href="../ref/settings.html#std:setting-MANAGERS"><tt class="xref std std-setting docutils literal"><span class="pre">MANAGERS</span></tt></a> setting whenever your code raises a 404 and the request has a referer. (It doesn’t bother to e-mail for 404s that don’t have a referer – those are usually just people typing in broken URLs or broken Web ‘bots).</p> <p>You can tell Django to stop reporting particular 404s by tweaking the <a class="reference internal" href="../ref/settings.html#std:setting-IGNORABLE_404_ENDS"><tt class="xref std std-setting docutils literal"><span class="pre">IGNORABLE_404_ENDS</span></tt></a> and <a class="reference internal" href="../ref/settings.html#std:setting-IGNORABLE_404_STARTS"><tt class="xref std std-setting docutils literal"><span class="pre">IGNORABLE_404_STARTS</span></tt></a> settings. Both should be a tuple of strings. For example:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">IGNORABLE_404_ENDS</span> <span class="o">=</span> <span class="p">(</span><span class="s">'.php'</span><span class="p">,</span> <span class="s">'.cgi'</span><span class="p">)</span> <span class="n">IGNORABLE_404_STARTS</span> <span class="o">=</span> <span class="p">(</span><span class="s">'/phpmyadmin/'</span><span class="p">,)</span> </pre></div> </div> <p>In this example, a 404 to any URL ending with <tt class="docutils literal"><span class="pre">.php</span></tt> or <tt class="docutils literal"><span class="pre">.cgi</span></tt> will <em>not</em> be reported. Neither will any URL starting with <tt class="docutils literal"><span class="pre">/phpmyadmin/</span></tt>.</p> <p>The best way to disable this behavior is to set <a class="reference internal" href="../ref/settings.html#std:setting-SEND_BROKEN_LINK_EMAILS"><tt class="xref std std-setting docutils literal"><span class="pre">SEND_BROKEN_LINK_EMAILS</span></tt></a> to <tt class="xref docutils literal"><span class="pre">False</span></tt>.</p> <div class="admonition-see-also admonition seealso"> <p class="first admonition-title">See also</p> <p class="last">You can also set up custom error reporting by writing a custom piece of <a class="reference internal" href="../topics/http/middleware.html#exception-middleware"><em>exception middleware</em></a>. If you do write custom error handling, it's a good idea to emulate Django's built-in error handling and only report/log errors if <a class="reference internal" href="../ref/settings.html#std:setting-DEBUG"><tt class="xref std std-setting docutils literal"><span class="pre">DEBUG</span></tt></a> is <tt class="xref docutils literal"><span class="pre">False</span></tt>.</p> </div> <div class="admonition-see-also admonition seealso"> <p class="first admonition-title">See also</p> <div class="versionadded"> <span class="title">New in Django 1.3:</span> <a class="reference internal" href="../releases/1.3.html"><em>Please, see the release notes</em></a></div> <p class="last">404 errors are logged using the logging framework. By default, these log records are ignored, but you can use them for error reporting by writing a handler and <a class="reference internal" href="../topics/logging.html"><em>configuring logging</em></a> appropriately.</p> </div> </div> </div> </div> </div> </div> <div class="yui-b" id="sidebar"> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="../contents.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">Error reporting via e-mail</a><ul> <li><a class="reference internal" href="#server-errors">Server errors</a></li> <li><a class="reference internal" href="#errors">404 errors</a></li> </ul> </li> </ul> <h3>Browse</h3> <ul> <li>Prev: <a href="deployment/modpython.html">How to use Django with Apache and mod_python</a></li> <li>Next: <a href="initial-data.html">Providing initial data for models</a></li> </ul> <h3>You are here:</h3> <ul> <li> <a href="../index.html">Django v1.3.1 documentation</a> <ul><li><a href="index.html">“How-to” guides</a> <ul><li>Error reporting via e-mail</li></ul> </li></ul> </li> </ul> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/howto/error-reporting.txt" rel="nofollow">Show Source</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="../search.html" method="get"> <input type="text" name="q" size="18" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <h3>Last update:</h3> <p class="topless">Sep 10, 2011</p> </div> </div> <div id="ft"> <div class="nav"> « <a href="deployment/modpython.html" title="How to use Django with Apache and mod_python">previous</a> | <a href="index.html" title="&#8220;How-to&#8221; guides" accesskey="U">up</a> | <a href="initial-data.html" title="Providing initial data for models">next</a> »</div> </div> </div> <div class="clearer"></div> </div> </body> </html>