{"title":"Error reporting","version":"2.0","locale":"en","docname":"howto/error-reporting","url":"/en/2.0/howto/error-reporting/","canonical":"https://djangodocs.dev/en/2.0/howto/error-reporting/","summary":"When you’re running a public site you should always turn off the DEBUG setting. That will make your server run much faster, and will also prevent malicious users…","html":"<h1>Error reporting<a class=\"heading-anchor\" href=\"#error-reporting\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>When you’re running a public site you should always turn off the\n<a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a> setting. That will make your server run much faster, and will\nalso prevent malicious users from seeing details of your application that can be\nrevealed by the error pages.</p>\n<p>However, running with <a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a> set to <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code> means you’ll never see\nerrors generated by your site – everyone will just see your public error pages.\nYou need to keep track of errors that occur in deployed sites, so Django can be\nconfigured to create reports with details about those errors.</p>\n<section id=\"email-reports\">\n<h2>Email reports<a class=\"heading-anchor\" href=\"#email-reports\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"server-errors\">\n<h3>Server errors<a class=\"heading-anchor\" href=\"#server-errors\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>When <a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a> is <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>, Django will email the users listed in the\n<a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-ADMINS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">ADMINS</span></code></a> setting whenever your code raises an unhandled exception and\nresults in an internal server error (HTTP status code 500). This gives the\nadministrators immediate notification of any errors. The <a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-ADMINS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">ADMINS</span></code></a> will\nget a description of the error, a complete Python traceback, and details about\nthe HTTP request that caused the error.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>In order to send email, Django requires a few settings telling it\nhow to connect to your mail server. At the very least, you’ll need\nto specify <a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-EMAIL_HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_HOST</span></code></a> and possibly\n<a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-EMAIL_HOST_USER\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_HOST_USER</span></code></a> and <a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-EMAIL_HOST_PASSWORD\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_HOST_PASSWORD</span></code></a>,\nthough other settings may be also required depending on your mail\nserver’s configuration. Consult <a class=\"reference internal\" href=\"/en/2.0/ref/settings/\"><span class=\"doc\">the Django settings\ndocumentation</span></a> for a full list of email-related\nsettings.</p>\n</aside>\n<p>By default, Django will send email from <a class=\"reference external\" href=\"mailto:root&#37;&#52;&#48;localhost\">root<span>&#64;</span>localhost</a>. However, some mail\nproviders reject all email from this address. To use a different sender\naddress, modify the <a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-SERVER_EMAIL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SERVER_EMAIL</span></code></a> setting.</p>\n<p>To activate this behavior, put the email addresses of the recipients in the\n<a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-ADMINS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">ADMINS</span></code></a> setting.</p>\n<aside class=\"admonition admonition-seealso\">\n<p class=\"admonition-title\">See also</p>\n<p>Server error emails are sent using the logging framework, so you can\ncustomize this behavior by <a class=\"reference internal\" href=\"/en/2.0/topics/logging/\"><span class=\"doc\">customizing your logging configuration</span></a>.</p>\n</aside>\n</section>\n<section id=\"errors\">\n<h3>404 errors<a class=\"heading-anchor\" href=\"#errors\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Django can also be configured to email errors about broken links (404 “page\nnot found” errors). Django sends emails about 404 errors when:</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a> is <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>;</p></li>\n<li><p>Your <a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-MIDDLEWARE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MIDDLEWARE</span></code></a> setting includes\n<a class=\"reference internal\" href=\"/en/2.0/ref/middleware/#django.middleware.common.BrokenLinkEmailsMiddleware\" title=\"django.middleware.common.BrokenLinkEmailsMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.middleware.common.BrokenLinkEmailsMiddleware</span></code></a>.</p></li>\n</ul>\n<p>If those conditions are met, Django will email the users listed in the\n<a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-MANAGERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MANAGERS</span></code></a> setting whenever your code raises a 404 and the request has\na referer. It doesn’t bother to email for 404s that don’t have a referer –\nthose are usually just people typing in broken URLs or broken Web bots. It also\nignores 404s when the referer is equal to the requested URL, since this\nbehavior is from broken Web bots too.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p><a class=\"reference internal\" href=\"/en/2.0/ref/middleware/#django.middleware.common.BrokenLinkEmailsMiddleware\" title=\"django.middleware.common.BrokenLinkEmailsMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">BrokenLinkEmailsMiddleware</span></code></a> must appear\nbefore other middleware that intercepts 404 errors, such as\n<a class=\"reference internal\" href=\"/en/2.0/ref/middleware/#django.middleware.locale.LocaleMiddleware\" title=\"django.middleware.locale.LocaleMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">LocaleMiddleware</span></code></a> or\n<a class=\"reference internal\" href=\"/en/2.0/ref/contrib/flatpages/#django.contrib.flatpages.middleware.FlatpageFallbackMiddleware\" title=\"django.contrib.flatpages.middleware.FlatpageFallbackMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">FlatpageFallbackMiddleware</span></code></a>.\nPut it towards the top of your <a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-MIDDLEWARE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MIDDLEWARE</span></code></a> setting.</p>\n</aside>\n<p>You can tell Django to stop reporting particular 404s by tweaking the\n<a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-IGNORABLE_404_URLS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">IGNORABLE_404_URLS</span></code></a> setting. It should be a list of compiled\nregular expression objects. For example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">import</span><span class=\"w\"> </span><span class=\"nn\">re</span>\n<span class=\"n\">IGNORABLE_404_URLS</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"n\">re</span><span class=\"o\">.</span><span class=\"n\">compile</span><span class=\"p\">(</span><span class=\"sa\">r</span><span class=\"s1\">&#39;\\.(php|cgi)$&#39;</span><span class=\"p\">),</span>\n    <span class=\"n\">re</span><span class=\"o\">.</span><span class=\"n\">compile</span><span class=\"p\">(</span><span class=\"sa\">r</span><span class=\"s1\">&#39;^/phpmyadmin/&#39;</span><span class=\"p\">),</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>In this example, a 404 to any URL ending with <code class=\"docutils literal notranslate\"><span class=\"pre\">.php</span></code> or <code class=\"docutils literal notranslate\"><span class=\"pre\">.cgi</span></code> will <em>not</em> be\nreported. Neither will any URL starting with <code class=\"docutils literal notranslate\"><span class=\"pre\">/phpmyadmin/</span></code>.</p>\n<p>The following example shows how to exclude some conventional URLs that browsers and\ncrawlers often request:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">import</span><span class=\"w\"> </span><span class=\"nn\">re</span>\n<span class=\"n\">IGNORABLE_404_URLS</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"n\">re</span><span class=\"o\">.</span><span class=\"n\">compile</span><span class=\"p\">(</span><span class=\"sa\">r</span><span class=\"s1\">&#39;^/apple-touch-icon.*\\.png$&#39;</span><span class=\"p\">),</span>\n    <span class=\"n\">re</span><span class=\"o\">.</span><span class=\"n\">compile</span><span class=\"p\">(</span><span class=\"sa\">r</span><span class=\"s1\">&#39;^/favicon\\.ico$&#39;</span><span class=\"p\">),</span>\n    <span class=\"n\">re</span><span class=\"o\">.</span><span class=\"n\">compile</span><span class=\"p\">(</span><span class=\"sa\">r</span><span class=\"s1\">&#39;^/robots\\.txt$&#39;</span><span class=\"p\">),</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>(Note that these are regular expressions, so we put a backslash in front of\nperiods to escape them.)</p>\n<p>If you’d like to customize the behavior of\n<a class=\"reference internal\" href=\"/en/2.0/ref/middleware/#django.middleware.common.BrokenLinkEmailsMiddleware\" title=\"django.middleware.common.BrokenLinkEmailsMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.middleware.common.BrokenLinkEmailsMiddleware</span></code></a> further (for\nexample to ignore requests coming from web crawlers), you should subclass it\nand override its methods.</p>\n<aside class=\"admonition admonition-seealso\">\n<p class=\"admonition-title\">See also</p>\n<p>404 errors are logged using the logging framework. By default, these log\nrecords are ignored, but you can use them for error reporting by writing a\nhandler and <a class=\"reference internal\" href=\"/en/2.0/topics/logging/\"><span class=\"doc\">configuring logging</span></a> appropriately.</p>\n</aside>\n</section>\n</section>\n<section id=\"filtering-error-reports\">\n<span id=\"id1\"></span><h2>Filtering error reports<a class=\"heading-anchor\" href=\"#filtering-error-reports\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Warning</p>\n<p>Filtering sensitive data is a hard problem, and it’s nearly impossible to\nguarantee that sensitive data won’t leak into an error report. Therefore,\nerror reports should only be available to trusted team members and you\nshould avoid transmitting error reports unencrypted over the Internet\n(such as through email).</p>\n</aside>\n<section id=\"filtering-sensitive-information\">\n<h3>Filtering sensitive information<a class=\"heading-anchor\" href=\"#filtering-sensitive-information\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Error reports are really helpful for debugging errors, so it is generally\nuseful to record as much relevant information about those errors as possible.\nFor example, by default Django records the <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Stack_trace\">full traceback</a> for the\nexception raised, each <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Stack_frame\">traceback frame</a>’s local variables, and the\n<a class=\"reference internal\" href=\"/en/2.0/ref/request-response/#django.http.HttpRequest\" title=\"django.http.HttpRequest\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">HttpRequest</span></code></a>’s <a class=\"reference internal\" href=\"/en/2.0/ref/request-response/#httprequest-attributes\"><span class=\"std std-ref\">attributes</span></a>.</p>\n<p>However, sometimes certain types of information may be too sensitive and thus\nmay not be appropriate to be kept track of, for example a user’s password or\ncredit card number. So in addition to filtering out settings that appear to be\nsensitive as described in the <a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a> documentation, Django offers a\nset of function decorators to help you control which information should be\nfiltered out of error reports in a production environment (that is, where\n<a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a> is set to <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>): <a class=\"reference internal\" href=\"#django.views.decorators.debug.sensitive_variables\" title=\"django.views.decorators.debug.sensitive_variables\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">sensitive_variables()</span></code></a> and\n<a class=\"reference internal\" href=\"#django.views.decorators.debug.sensitive_post_parameters\" title=\"django.views.decorators.debug.sensitive_post_parameters\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">sensitive_post_parameters()</span></code></a>.</p>\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.views.decorators.debug.sensitive_variables\">\n<span class=\"sig-name descname\"><span class=\"pre\">sensitive_variables</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\"><span class=\"pre\">*</span></span><span class=\"n\"><span class=\"pre\">variables</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.decorators.debug.sensitive_variables\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>If a function (either a view or any regular callback) in your code uses\nlocal variables susceptible to contain sensitive information, you may\nprevent the values of those variables from being included in error reports\nusing the <code class=\"docutils literal notranslate\"><span class=\"pre\">sensitive_variables</span></code> decorator:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.views.decorators.debug</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">sensitive_variables</span>\n\n<span class=\"nd\">@sensitive_variables</span><span class=\"p\">(</span><span class=\"s1\">&#39;user&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;pw&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;cc&#39;</span><span class=\"p\">)</span>\n<span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">process_info</span><span class=\"p\">(</span><span class=\"n\">user</span><span class=\"p\">):</span>\n    <span class=\"n\">pw</span> <span class=\"o\">=</span> <span class=\"n\">user</span><span class=\"o\">.</span><span class=\"n\">pass_word</span>\n    <span class=\"n\">cc</span> <span class=\"o\">=</span> <span class=\"n\">user</span><span class=\"o\">.</span><span class=\"n\">credit_card_number</span>\n    <span class=\"n\">name</span> <span class=\"o\">=</span> <span class=\"n\">user</span><span class=\"o\">.</span><span class=\"n\">name</span>\n    <span class=\"o\">...</span>\n</code></pre></div>\n<p>In the above example, the values for the <code class=\"docutils literal notranslate\"><span class=\"pre\">user</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">pw</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">cc</span></code>\nvariables will be hidden and replaced with stars (**********) in the\nerror reports, whereas the value of the <code class=\"docutils literal notranslate\"><span class=\"pre\">name</span></code> variable will be\ndisclosed.</p>\n<p>To systematically hide all local variables of a function from error logs,\ndo not provide any argument to the <code class=\"docutils literal notranslate\"><span class=\"pre\">sensitive_variables</span></code> decorator:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"nd\">@sensitive_variables</span><span class=\"p\">()</span>\n<span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">my_function</span><span class=\"p\">():</span>\n    <span class=\"o\">...</span>\n</code></pre></div>\n<aside class=\"admonition-when-using-multiple-decorators admonition\">\n<p class=\"admonition-title\">When using multiple decorators</p>\n<p>If the variable you want to hide is also a function argument (e.g.\n‘<code class=\"docutils literal notranslate\"><span class=\"pre\">user</span></code>’ in the following example), and if the decorated function has\nmultiple decorators, then make sure to place <code class=\"docutils literal notranslate\"><span class=\"pre\">&#64;sensitive_variables</span></code>\nat the top of the decorator chain. This way it will also hide the\nfunction argument as it gets passed through the other decorators:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"nd\">@sensitive_variables</span><span class=\"p\">(</span><span class=\"s1\">&#39;user&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;pw&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;cc&#39;</span><span class=\"p\">)</span>\n<span class=\"nd\">@some_decorator</span>\n<span class=\"nd\">@another_decorator</span>\n<span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">process_info</span><span class=\"p\">(</span><span class=\"n\">user</span><span class=\"p\">):</span>\n    <span class=\"o\">...</span>\n</code></pre></div>\n</aside>\n</dd></dl>\n\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.views.decorators.debug.sensitive_post_parameters\">\n<span class=\"sig-name descname\"><span class=\"pre\">sensitive_post_parameters</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\"><span class=\"pre\">*</span></span><span class=\"n\"><span class=\"pre\">parameters</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.decorators.debug.sensitive_post_parameters\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>If one of your views receives an <a class=\"reference internal\" href=\"/en/2.0/ref/request-response/#django.http.HttpRequest\" title=\"django.http.HttpRequest\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">HttpRequest</span></code></a> object\nwith <a class=\"reference internal\" href=\"/en/2.0/ref/request-response/#django.http.HttpRequest.POST\" title=\"django.http.HttpRequest.POST\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">POST</span> <span class=\"pre\">parameters</span></code></a> susceptible to\ncontain sensitive information, you may prevent the values of those\nparameters from being included in the error reports using the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">sensitive_post_parameters</span></code> decorator:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.views.decorators.debug</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">sensitive_post_parameters</span>\n\n<span class=\"nd\">@sensitive_post_parameters</span><span class=\"p\">(</span><span class=\"s1\">&#39;pass_word&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;credit_card_number&#39;</span><span class=\"p\">)</span>\n<span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">record_user_profile</span><span class=\"p\">(</span><span class=\"n\">request</span><span class=\"p\">):</span>\n    <span class=\"n\">UserProfile</span><span class=\"o\">.</span><span class=\"n\">create</span><span class=\"p\">(</span>\n        <span class=\"n\">user</span><span class=\"o\">=</span><span class=\"n\">request</span><span class=\"o\">.</span><span class=\"n\">user</span><span class=\"p\">,</span>\n        <span class=\"n\">password</span><span class=\"o\">=</span><span class=\"n\">request</span><span class=\"o\">.</span><span class=\"n\">POST</span><span class=\"p\">[</span><span class=\"s1\">&#39;pass_word&#39;</span><span class=\"p\">],</span>\n        <span class=\"n\">credit_card</span><span class=\"o\">=</span><span class=\"n\">request</span><span class=\"o\">.</span><span class=\"n\">POST</span><span class=\"p\">[</span><span class=\"s1\">&#39;credit_card_number&#39;</span><span class=\"p\">],</span>\n        <span class=\"n\">name</span><span class=\"o\">=</span><span class=\"n\">request</span><span class=\"o\">.</span><span class=\"n\">POST</span><span class=\"p\">[</span><span class=\"s1\">&#39;name&#39;</span><span class=\"p\">],</span>\n    <span class=\"p\">)</span>\n    <span class=\"o\">...</span>\n</code></pre></div>\n<p>In the above example, the values for the <code class=\"docutils literal notranslate\"><span class=\"pre\">pass_word</span></code> and\n<code class=\"docutils literal notranslate\"><span class=\"pre\">credit_card_number</span></code> POST parameters will be hidden and replaced with\nstars (**********) in the request’s representation inside the error\nreports, whereas the value of the <code class=\"docutils literal notranslate\"><span class=\"pre\">name</span></code> parameter will be disclosed.</p>\n<p>To systematically hide all POST parameters of a request in error reports,\ndo not provide any argument to the <code class=\"docutils literal notranslate\"><span class=\"pre\">sensitive_post_parameters</span></code> decorator:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"nd\">@sensitive_post_parameters</span><span class=\"p\">()</span>\n<span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">my_view</span><span class=\"p\">(</span><span class=\"n\">request</span><span class=\"p\">):</span>\n    <span class=\"o\">...</span>\n</code></pre></div>\n<p>All POST parameters are systematically filtered out of error reports for\ncertain <a class=\"reference internal\" href=\"/en/2.0/topics/auth/default/#module-django.contrib.auth.views\" title=\"django.contrib.auth.views\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.contrib.auth.views</span></code></a> views (<code class=\"docutils literal notranslate\"><span class=\"pre\">login</span></code>,\n<code class=\"docutils literal notranslate\"><span class=\"pre\">password_reset_confirm</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">password_change</span></code>, and <code class=\"docutils literal notranslate\"><span class=\"pre\">add_view</span></code> and\n<code class=\"docutils literal notranslate\"><span class=\"pre\">user_change_password</span></code> in the <code class=\"docutils literal notranslate\"><span class=\"pre\">auth</span></code> admin) to prevent the leaking of\nsensitive information such as user passwords.</p>\n</dd></dl>\n\n</section>\n<section id=\"custom-error-reports\">\n<span id=\"id2\"></span><h3>Custom error reports<a class=\"heading-anchor\" href=\"#custom-error-reports\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>All <a class=\"reference internal\" href=\"#django.views.decorators.debug.sensitive_variables\" title=\"django.views.decorators.debug.sensitive_variables\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">sensitive_variables()</span></code></a> and <a class=\"reference internal\" href=\"#django.views.decorators.debug.sensitive_post_parameters\" title=\"django.views.decorators.debug.sensitive_post_parameters\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">sensitive_post_parameters()</span></code></a> do is,\nrespectively, annotate the decorated function with the names of sensitive\nvariables and annotate the <code class=\"docutils literal notranslate\"><span class=\"pre\">HttpRequest</span></code> object with the names of sensitive\nPOST parameters, so that this sensitive information can later be filtered out\nof reports when an error occurs. The actual filtering is done by Django’s\ndefault error reporter filter:\n<a class=\"reference internal\" href=\"#django.views.debug.SafeExceptionReporterFilter\" title=\"django.views.debug.SafeExceptionReporterFilter\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.views.debug.SafeExceptionReporterFilter</span></code></a>. This filter uses the\ndecorators’ annotations to replace the corresponding values with stars\n(**********) when the error reports are produced. If you wish to override or\ncustomize this default behavior for your entire site, you need to define your\nown filter class and tell Django to use it via the\n<a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-DEFAULT_EXCEPTION_REPORTER_FILTER\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEFAULT_EXCEPTION_REPORTER_FILTER</span></code></a> setting:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">DEFAULT_EXCEPTION_REPORTER_FILTER</span> <span class=\"o\">=</span> <span class=\"s1\">&#39;path.to.your.CustomExceptionReporterFilter&#39;</span>\n</code></pre></div>\n<p>You may also control in a more granular way which filter to use within any\ngiven view by setting the <code class=\"docutils literal notranslate\"><span class=\"pre\">HttpRequest</span></code>’s <code class=\"docutils literal notranslate\"><span class=\"pre\">exception_reporter_filter</span></code>\nattribute:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">my_view</span><span class=\"p\">(</span><span class=\"n\">request</span><span class=\"p\">):</span>\n    <span class=\"k\">if</span> <span class=\"n\">request</span><span class=\"o\">.</span><span class=\"n\">user</span><span class=\"o\">.</span><span class=\"n\">is_authenticated</span><span class=\"p\">:</span>\n        <span class=\"n\">request</span><span class=\"o\">.</span><span class=\"n\">exception_reporter_filter</span> <span class=\"o\">=</span> <span class=\"n\">CustomExceptionReporterFilter</span><span class=\"p\">()</span>\n    <span class=\"o\">...</span>\n</code></pre></div>\n<p>Your custom filter class needs to inherit from\n<a class=\"reference internal\" href=\"#django.views.debug.SafeExceptionReporterFilter\" title=\"django.views.debug.SafeExceptionReporterFilter\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.views.debug.SafeExceptionReporterFilter</span></code></a> and may override the\nfollowing methods:</p>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.views.debug.SafeExceptionReporterFilter\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">SafeExceptionReporterFilter</span></span><a class=\"heading-anchor\" href=\"#django.views.debug.SafeExceptionReporterFilter\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.views.debug.SafeExceptionReporterFilter.is_active\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">SafeExceptionReporterFilter.</span></span><span class=\"sig-name descname\"><span class=\"pre\">is_active</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">request</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.debug.SafeExceptionReporterFilter.is_active\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> to activate the filtering operated in the other methods.\nBy default the filter is active if <a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a> is <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.views.debug.SafeExceptionReporterFilter.get_post_parameters\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">SafeExceptionReporterFilter.</span></span><span class=\"sig-name descname\"><span class=\"pre\">get_post_parameters</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">request</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.debug.SafeExceptionReporterFilter.get_post_parameters\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns the filtered dictionary of POST parameters. By default it replaces\nthe values of sensitive parameters with stars (**********).</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.views.debug.SafeExceptionReporterFilter.get_traceback_frame_variables\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">SafeExceptionReporterFilter.</span></span><span class=\"sig-name descname\"><span class=\"pre\">get_traceback_frame_variables</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">request</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">tb_frame</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.debug.SafeExceptionReporterFilter.get_traceback_frame_variables\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns the filtered dictionary of local variables for the given traceback\nframe. By default it replaces the values of sensitive variables with stars\n(**********).</p>\n</dd></dl>\n\n<aside class=\"admonition admonition-seealso\">\n<p class=\"admonition-title\">See also</p>\n<p>You can also set up custom error reporting by writing a custom piece of\n<a class=\"reference internal\" href=\"/en/2.0/topics/http/middleware/#exception-middleware\"><span class=\"std std-ref\">exception middleware</span></a>. If you do write custom\nerror handling, it’s a good idea to emulate Django’s built-in error handling\nand only report/log errors if <a class=\"reference internal\" href=\"/en/2.0/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a> is <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>.</p>\n</aside>\n</section>\n</section>","rootId":"error-reporting","toc":[{"title":"Email reports","anchor":"email-reports","children":[{"title":"Server errors","anchor":"server-errors","children":[]},{"title":"404 errors","anchor":"errors","children":[]}]},{"title":"Filtering error reports","anchor":"filtering-error-reports","children":[{"title":"Filtering sensitive information","anchor":"filtering-sensitive-information","children":[]},{"title":"Custom error reports","anchor":"custom-error-reports","children":[]}]}],"breadcrumbs":[{"docname":"howto/index","title":"“How-to” guides","url":"/en/2.0/howto/"}],"prev":{"docname":"howto/upgrade-version","title":"Upgrading Django to a newer version","url":"/en/2.0/howto/upgrade-version/"},"next":{"docname":"howto/initial-data","title":"Providing initial data for models","url":"/en/2.0/howto/initial-data/"},"formats":{"html":"/en/2.0/howto/error-reporting/","markdown":"/en/2.0/howto/error-reporting.md","json":"/en/2.0/howto/error-reporting.json"},"source":"https://github.com/django/django/blob/stable/2.0.x/docs/howto/error-reporting.txt","official":"https://docs.djangoproject.com/en/2.0/howto/error-reporting/","inVersions":["dev","6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10","1.9","1.8"],"inLocales":["en","zh-hans","fr","ja","id","pt-br","ko","es","el","pl"]}