{"title":"Pelaporan kesalahan","version":"3.1","locale":"id","docname":"howto/error-reporting","url":"/id/3.1/howto/error-reporting/","canonical":"https://djangodocs.dev/id/3.1/howto/error-reporting/","summary":"Ketika anda sedang menjalankan situs umum anda harus selalu mematikan pengaturan DEBUG.","html":"<h1>Pelaporan kesalahan<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>Ketika anda sedang menjalankan situs umum anda harus selalu mematikan pengaturan <a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\">DEBUG</code></a>. Itu akan membuat peladen anda berjalan lebih cepat, dan juga akan mencegah pengguna hahat dari melihat rincian dari aplikasi anda yang dapat diungkap dengan kesalahan halaman.</p>\n<p>However, running with <a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\">DEBUG</code></a> set to <code class=\"docutils literal notranslate\">False</code> means you'll never see\nerrors generated by your site -- everyone will instead see your public error\npages. You need to keep track of errors that occur in deployed sites, so Django\ncan be configured to create reports with details about those errors.</p>\n<section id=\"email-reports\">\n<h2>Surel laporan<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>Kesalahan peladen<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=\"/id/3.1/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\">DEBUG</code></a> is <code class=\"docutils literal notranslate\">False</code>, Django will email the users listed in the\n<a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-ADMINS\"><code class=\"xref std std-setting docutils literal notranslate\">ADMINS</code></a> setting whenever your code raises an unhandled exception and\nresults in an internal server error (strictly speaking, for any response with\nan HTTP status code of 500 or greater). This gives the administrators immediate\nnotification of any errors. The <a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-ADMINS\"><code class=\"xref std std-setting docutils literal notranslate\">ADMINS</code></a> will get a description of the\nerror, a complete Python traceback, and details about the HTTP request that\ncaused the error.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Catatan</p>\n<p>Agar mengirim surel, Django membutuhkan beberapa pengaturan mengatakannya bagaimana terhubung ke peladen surat anda. Setidaknya, anda akan butuh menentukan <a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-EMAIL_HOST\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST</code></a> dan kemungkinan <a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-EMAIL_HOST_USER\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST_USER</code></a> dan <a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-EMAIL_HOST_PASSWORD\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST_PASSWORD</code></a>, meskipun pengaturan lainnya mungkin tidak juga dibutuhkan tergantung pada konfigurasi peladen surat anda. Rundingkan <a class=\"reference internal\" href=\"/id/3.1/ref/settings/\"><span class=\"doc\">the Django settings documentation</span></a> untuk daftar penuh dari pengaturan terkait-surel.</p>\n</aside>\n<p>Secara awal, Django akan mengirim surel dari <a class=\"reference external\" href=\"mailto:root&#37;&#52;&#48;localhost\">root<span>&#64;</span>localhost</a>. Bagaimanapun, beberapa penyedia surat menolak semua surel dari alamat ini. Untuk menggunakan alamat pengirim berbeda, rubah pengaturan <a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-SERVER_EMAIL\"><code class=\"xref std std-setting docutils literal notranslate\">SERVER_EMAIL</code></a>.</p>\n<p>Untuk mengaktifkan perilaku ini, masukkan alamat surel dari penerima di bagian <a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-ADMINS\"><code class=\"xref std std-setting docutils literal notranslate\">ADMINS</code></a>.</p>\n<aside class=\"admonition admonition-seealso\" role=\"note\">\n<p class=\"admonition-title\">Lihat juga</p>\n<p>Surel kesalahan peladen dikirim menggunakan kerangka pencatatan, jadi anda dapat menyesuaikan perilaku ini dengan <a class=\"reference internal\" href=\"/id/3.1/topics/logging/\"><span class=\"doc\">customizing your logging configuration</span></a>.</p>\n</aside>\n</section>\n<section id=\"errors\">\n<h3>kesalahan 404<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 juga dapat dikonfirgasi untuk mengirimkan surel kesalahan tentang tautan yang tidak ditemukan (404 &quot;page not found&quot; errors). Django mengirim surel tentang error 404 ketika:</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\">DEBUG</code></a> adalah <code class=\"docutils literal notranslate\">False</code>;</p></li>\n<li><p>Pengaturan <a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-MIDDLEWARE\"><code class=\"xref std std-setting docutils literal notranslate\">MIDDLEWARE</code></a> anda termasuk <a class=\"reference internal\" href=\"/id/3.1/ref/middleware/#django.middleware.common.BrokenLinkEmailsMiddleware\" title=\"django.middleware.common.BrokenLinkEmailsMiddleware\"><code class=\"xref py py-class docutils literal notranslate\">django.middleware.common.BrokenLinkEmailsMiddleware</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=\"/id/3.1/ref/settings/#std-setting-MANAGERS\"><code class=\"xref std std-setting docutils literal notranslate\">MANAGERS</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 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\">Catatan</p>\n<p><a class=\"reference internal\" href=\"/id/3.1/ref/middleware/#django.middleware.common.BrokenLinkEmailsMiddleware\" title=\"django.middleware.common.BrokenLinkEmailsMiddleware\"><code class=\"xref py py-class docutils literal notranslate\">BrokenLinkEmailsMiddleware</code></a> harus muncul sebelum middleware lain yang mencegat kesalahan 404, seperti <a class=\"reference internal\" href=\"/id/3.1/ref/middleware/#django.middleware.locale.LocaleMiddleware\" title=\"django.middleware.locale.LocaleMiddleware\"><code class=\"xref py py-class docutils literal notranslate\">LocaleMiddleware</code></a> atau <a class=\"reference internal\" href=\"/id/3.1/ref/contrib/flatpages/#django.contrib.flatpages.middleware.FlatpageFallbackMiddleware\" title=\"django.contrib.flatpages.middleware.FlatpageFallbackMiddleware\"><code class=\"xref py py-class docutils literal notranslate\">FlatpageFallbackMiddleware</code></a>. Taruh itu menuju atas dari pengaturan <a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-MIDDLEWARE\"><code class=\"xref std std-setting docutils literal notranslate\">MIDDLEWARE</code></a> anda.</p>\n</aside>\n<p>Anda dapat memberitahu Django untuk menghentikan pelaporan tertentu 404 dengan merubah pengaturan <a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-IGNORABLE_404_URLS\"><code class=\"xref std std-setting docutils literal notranslate\">IGNORABLE_404_URLS</code></a>. Dia harus menjadi daftar dari obyek ungkapan biasa tersusun. Sebagai contoh:</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=\"nn\">re</span>\nIGNORABLE_404_URLS <span class=\"o\">=</span> <span class=\"p\">[</span>\n    re<span class=\"o\">.</span>compile<span class=\"p\">(</span><span class=\"sa\">r</span><span class=\"s1\">&#39;\\.(php|cgi)$&#39;</span><span class=\"p\">),</span>\n    re<span class=\"o\">.</span>compile<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>Dalam contoh ini, sebuah 404 pada setiap URL berakhiran dengan <code class=\"docutils literal notranslate\">.php</code> atau <code class=\"docutils literal notranslate\">.cgi</code> akan <em>tidak</em> dilaporkan. Juga tidak akan URL apapun dimulai dengan <code class=\"docutils literal notranslate\">/phpmyadmin/</code>.</p>\n<p>Contoh berikut menunjukkan bagaimana mengeluarkan beberapa URL biasa yang perambah dan penjilat sering diminta:</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=\"nn\">re</span>\nIGNORABLE_404_URLS <span class=\"o\">=</span> <span class=\"p\">[</span>\n    re<span class=\"o\">.</span>compile<span class=\"p\">(</span><span class=\"sa\">r</span><span class=\"s1\">&#39;^/apple-touch-icon.*\\.png$&#39;</span><span class=\"p\">),</span>\n    re<span class=\"o\">.</span>compile<span class=\"p\">(</span><span class=\"sa\">r</span><span class=\"s1\">&#39;^/favicon\\.ico$&#39;</span><span class=\"p\">),</span>\n    re<span class=\"o\">.</span>compile<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>(Perhatikan bahwa ini adalah regular expression, jadi kita tuliskan garis miring terbalik di depan titik untuk melepaskannya)</p>\n<p>Jika anda suka menyesuaikan perilaku dari <a class=\"reference internal\" href=\"/id/3.1/ref/middleware/#django.middleware.common.BrokenLinkEmailsMiddleware\" title=\"django.middleware.common.BrokenLinkEmailsMiddleware\"><code class=\"xref py py-class docutils literal notranslate\">django.middleware.common.BrokenLinkEmailsMiddleware</code></a> lebih lanjut (sebagai contoh untuk mengabaikan permintaan datang dari penjilat jaringan), anda harus mensubkelaskannya dan menimpa caranya.</p>\n<aside class=\"admonition admonition-seealso\" role=\"note\">\n<p class=\"admonition-title\">Lihat juga</p>\n<p>Kesalahan 404 dicatat menggunakan kerangka pencatatan. Secara awal, rekaman catatan ini diabaikan, tetapi anda dapat menggunakan mereka untuk kesalahan pelaporan dengan menulis sebuah penanganan <a class=\"reference internal\" href=\"/id/3.1/topics/logging/\"><span class=\"doc\">configuring logging</span></a> dengan benar.</p>\n</aside>\n</section>\n</section>\n<section id=\"filtering-error-reports\">\n<span id=\"id1\"></span><h2>Menyaring laporan kesalahan<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\">Peringatan</p>\n<p>Menyaring data sensitif adalah masalah sulit, dan hampir tidak mungkin menjamin bahwa data sensitif tidak akan bocor kedalam sebuah laporan kesalahan. Karena itu, laporan kesalahan harus hanya tersedia pada anggota tim yang dapat dipercaya dan harus menghindari perpindahan laporan kesalahan tidak disandikan di Internet (seperti melalui surel).</p>\n</aside>\n<section id=\"filtering-sensitive-information\">\n<h3>Menyaring informasi rahasia<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>Laporan kesalahan sangat membantu untuk memeriksa kesalahan, jadi dia umumnya berguna untuk merekam informasi terkait tentang kesalahan-kesalahan tersebut sebanyak mungkin. Sebagai contoh, secara awal rekaman Django <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Stack_trace\">full traceback</a> untuk dimunculkan pengecualian, setiap variabel lokal <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Stack_trace\">full traceback</a>, dan <a class=\"reference internal\" href=\"/id/3.1/ref/request-response/#httprequest-attributes\"><span class=\"std std-ref\">attributes</span></a> <a class=\"reference internal\" href=\"/id/3.1/ref/request-response/#django.http.HttpRequest\" title=\"django.http.HttpRequest\"><code class=\"xref py py-class docutils literal notranslate\">HttpRequest</code></a>.</p>\n<p>Bagaimanapun, terkadang jenis-jenis informasi tertentu mungkin terlalu sensitif dan dengan demikian mungkin tidak sesuai untuk terus melacak, sebagai contoh, sandi pengguna atau angka kartu kredit. Jadi di tambahaan untuk menyaring pengaturan yang muncul menjadi sensitif seperti digambarkan dalam dokumentasi <a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\">DEBUG</code></a>, Django menawarkan sekumpulan fungsi penghias untuk membantu anda mengendalikan informasi mana harus disaring dari laporan kesalahan dalam lingkungan produksi (yaitu, dimana <a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\">DEBUG</code></a> disetel ke <code class=\"docutils literal notranslate\">False</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\">sensitive_variables()</code></a> dan <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\">sensitive_post_parameters()</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\">sensitive_variables</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">*</span>variables</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>Jika sebuah fungsi (baik sebuah tampilan atau callback umum apapun) dalam kode anda menggunakan variabel lokal rentan mengandung informasi sensitif, anda mungkin mencegah nilai-nilai variabel tersebut dari menjadi disertakan dalam laporan kesalahan menggunakan penghias <code class=\"docutils literal notranslate\">sensitive_variables</code>:</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=\"nn\">django.views.decorators.debug</span> <span class=\"kn\">import</span> sensitive_variables\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=\"nf\">process_info</span><span class=\"p\">(</span>user<span class=\"p\">):</span>\n    pw <span class=\"o\">=</span> user<span class=\"o\">.</span>pass_word\n    cc <span class=\"o\">=</span> user<span class=\"o\">.</span>credit_card_number\n    name <span class=\"o\">=</span> user<span class=\"o\">.</span>name\n    <span class=\"o\">...</span>\n</code></pre></div>\n<p>In the above example, the values for the <code class=\"docutils literal notranslate\">user</code>, <code class=\"docutils literal notranslate\">pw</code> and <code class=\"docutils literal notranslate\">cc</code>\nvariables will be hidden and replaced with stars (<code class=\"docutils literal notranslate\">**********</code>)\nin the error reports, whereas the value of the <code class=\"docutils literal notranslate\">name</code> variable will be\ndisclosed.</p>\n<p>Untuk secara sistematis menyembunyikan semua variabel lokal dari sebuah fungsi dari laporan kesalahan, jangan menyediakan argumen apapun pada decorator <code class=\"docutils literal notranslate\">sensitive_variables</code>:</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=\"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\" role=\"note\">\n<p class=\"admonition-title\">Ketika menggunakan sejumlah dekorator</p>\n<p>Jika variabel anda ingin sembunyikan adalah juga argumen fungsi (sebagai contoh '<code class=\"docutils literal notranslate\">user</code>’ dalam contoh berikut), dan jika fungsi dihiasi mempunyai banyak decorator, kemudian pastikan menempatkan <code class=\"docutils literal notranslate\">&#64;sensitive_variables</code> pda atas dari rantai decorator. Cara ini dia akan juga menyembunyikan argumen fungsi ketika dia mendapatkan dilewati melalui decorator lain:</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=\"nf\">process_info</span><span class=\"p\">(</span>user<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\">sensitive_post_parameters</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">*</span>parameters</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>Jika satu dari tampilan anda menerima sebuah obyek <a class=\"reference internal\" href=\"/id/3.1/ref/request-response/#django.http.HttpRequest\" title=\"django.http.HttpRequest\"><code class=\"xref py py-class docutils literal notranslate\">HttpRequest</code></a> dengan <a class=\"reference internal\" href=\"/id/3.1/ref/request-response/#django.http.HttpRequest.POST\" title=\"django.http.HttpRequest.POST\"><code class=\"xref py py-attr docutils literal notranslate\">POST parameters</code></a> rentan untuk mengandung informasi sensitif, anda mungkin mencegah nilai-nilai dari parameter tersebut dari menjadi disertakan dalam laporan kesalahan menggunakan penghias <code class=\"docutils literal notranslate\">sensitive_post_parameters</code>:</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=\"nn\">django.views.decorators.debug</span> <span class=\"kn\">import</span> sensitive_post_parameters\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=\"nf\">record_user_profile</span><span class=\"p\">(</span>request<span class=\"p\">):</span>\n    UserProfile<span class=\"o\">.</span>create<span class=\"p\">(</span>\n        user<span class=\"o\">=</span>request<span class=\"o\">.</span>user<span class=\"p\">,</span>\n        password<span class=\"o\">=</span>request<span class=\"o\">.</span>POST<span class=\"p\">[</span><span class=\"s1\">&#39;pass_word&#39;</span><span class=\"p\">],</span>\n        credit_card<span class=\"o\">=</span>request<span class=\"o\">.</span>POST<span class=\"p\">[</span><span class=\"s1\">&#39;credit_card_number&#39;</span><span class=\"p\">],</span>\n        name<span class=\"o\">=</span>request<span class=\"o\">.</span>POST<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\">pass_word</code> and\n<code class=\"docutils literal notranslate\">credit_card_number</code> POST parameters will be hidden and replaced with\nstars (<code class=\"docutils literal notranslate\">**********</code>) in the request's representation inside the\nerror reports, whereas the value of the <code class=\"docutils literal notranslate\">name</code> parameter will be\ndisclosed.</p>\n<p>Untuk secara sistematis menyembunyikan semua parameter POST dari sebuah permintaan dalam laporan kesalahan, jangan menyediakan argumen apapun pada decorator <code class=\"docutils literal notranslate\">sensitive_variables</code>:</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=\"nf\">my_view</span><span class=\"p\">(</span>request<span class=\"p\">):</span>\n    <span class=\"o\">...</span>\n</code></pre></div>\n<p>Semua parameter POST adalah sistematis disaring keluar dari laporan kesalahan untuk tampilan <a class=\"reference internal\" href=\"/id/3.1/topics/auth/default/#module-django.contrib.auth.views\" title=\"django.contrib.auth.views\"><code class=\"xref py py-mod docutils literal notranslate\">django.contrib.auth.views</code></a> tertentu (<code class=\"docutils literal notranslate\">login</code>, <code class=\"docutils literal notranslate\">password_reset_confirm</code>, <code class=\"docutils literal notranslate\">password_change</code>, dan <code class=\"docutils literal notranslate\">add_view</code> dan <code class=\"docutils literal notranslate\">user_change_password</code> dalam admin <code class=\"docutils literal notranslate\">auth</code>) untuk mencegah dari pembocoran dari informasi sensitif seperti sandi pengguna.</p>\n</dd></dl>\n\n</section>\n<section id=\"custom-error-reports\">\n<span id=\"id2\"></span><h3>Penyesuaian laporan kesalahan<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\">sensitive_variables()</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\">sensitive_post_parameters()</code></a> do is,\nrespectively, annotate the decorated function with the names of sensitive\nvariables and annotate the <code class=\"docutils literal notranslate\">HttpRequest</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\">django.views.debug.SafeExceptionReporterFilter</code></a>. This filter uses the\ndecorators' annotations to replace the corresponding values with stars\n(<code class=\"docutils literal notranslate\">**********</code>) when the error reports are produced. If you wish to\noverride or customize this default behavior for your entire site, you need to\ndefine your own filter class and tell Django to use it via the\n<a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-DEFAULT_EXCEPTION_REPORTER_FILTER\"><code class=\"xref std std-setting docutils literal notranslate\">DEFAULT_EXCEPTION_REPORTER_FILTER</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>DEFAULT_EXCEPTION_REPORTER_FILTER <span class=\"o\">=</span> <span class=\"s1\">&#39;path.to.your.CustomExceptionReporterFilter&#39;</span>\n</code></pre></div>\n<p>Anda dapat juga mengendalikan cara lebih kecil penyaring mana untuk digunakan dalam tampilan yang diberikan oleh pengaturan atribut <code class=\"docutils literal notranslate\">exception_reporter_filter</code> <code class=\"docutils literal notranslate\">HttpRequest</code>:</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=\"nf\">my_view</span><span class=\"p\">(</span>request<span class=\"p\">):</span>\n    <span class=\"k\">if</span> request<span class=\"o\">.</span>user<span class=\"o\">.</span>is_authenticated<span class=\"p\">:</span>\n        request<span class=\"o\">.</span>exception_reporter_filter <span class=\"o\">=</span> CustomExceptionReporterFilter<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\">django.views.debug.SafeExceptionReporterFilter</code></a> and may override the\nfollowing attributes and 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\">class</span> </em><span class=\"sig-name descname\">SafeExceptionReporterFilter</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><dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.views.debug.SafeExceptionReporterFilter.cleansed_substitute\">\n<span class=\"sig-name descname\">cleansed_substitute</span><a class=\"heading-anchor\" href=\"#django.views.debug.SafeExceptionReporterFilter.cleansed_substitute\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><aside class=\"version-note version-added\" data-version=\"3.1\" role=\"note\">\n<p class=\"version-note-title\">New in Django 3.1</p></aside>\n<p>The string value to replace sensitive value with. By default it\nreplaces the values of sensitive variables with stars\n(<code class=\"docutils literal notranslate\">**********</code>).</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.views.debug.SafeExceptionReporterFilter.hidden_settings\">\n<span class=\"sig-name descname\">hidden_settings</span><a class=\"heading-anchor\" href=\"#django.views.debug.SafeExceptionReporterFilter.hidden_settings\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><aside class=\"version-note version-added\" data-version=\"3.1\" role=\"note\">\n<p class=\"version-note-title\">New in Django 3.1</p></aside>\n<p>A compiled regular expression object used to match settings and\n<code class=\"docutils literal notranslate\">request.META</code> values considered as sensitive. By default equivalent\nto:</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=\"nn\">re</span>\n\nre<span class=\"o\">.</span>compile<span class=\"p\">(</span><span class=\"sa\">r</span><span class=\"s1\">&#39;API|TOKEN|KEY|SECRET|PASS|SIGNATURE&#39;</span><span class=\"p\">,</span> flags<span class=\"o\">=</span>re<span class=\"o\">.</span>IGNORECASE<span class=\"p\">)</span>\n</code></pre></div>\n</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-name descname\">is_active</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">request</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\">True</code> to activate the filtering in\n<a class=\"reference internal\" href=\"#django.views.debug.SafeExceptionReporterFilter.get_post_parameters\" title=\"django.views.debug.SafeExceptionReporterFilter.get_post_parameters\"><code class=\"xref py py-meth docutils literal notranslate\">get_post_parameters()</code></a> and <a class=\"reference internal\" href=\"#django.views.debug.SafeExceptionReporterFilter.get_traceback_frame_variables\" title=\"django.views.debug.SafeExceptionReporterFilter.get_traceback_frame_variables\"><code class=\"xref py py-meth docutils literal notranslate\">get_traceback_frame_variables()</code></a>.\nBy default the filter is active if <a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\">DEBUG</code></a> is <code class=\"docutils literal notranslate\">False</code>. Note\nthat sensitive <code class=\"docutils literal notranslate\">request.META</code> values are always filtered along with\nsensitive setting values, as described in the <a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\">DEBUG</code></a>\ndocumentation.</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-name descname\">get_post_parameters</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">request</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. Sensitive values\nare replaced with <a class=\"reference internal\" href=\"#django.views.debug.SafeExceptionReporterFilter.cleansed_substitute\" title=\"django.views.debug.SafeExceptionReporterFilter.cleansed_substitute\"><code class=\"xref py py-attr docutils literal notranslate\">cleansed_substitute</code></a>.</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-name descname\">get_traceback_frame_variables</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">request</em>, <em class=\"sig-param\">tb_frame</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\ntraceback frame. Sensitive values are replaced with\n<a class=\"reference internal\" href=\"#django.views.debug.SafeExceptionReporterFilter.cleansed_substitute\" title=\"django.views.debug.SafeExceptionReporterFilter.cleansed_substitute\"><code class=\"xref py py-attr docutils literal notranslate\">cleansed_substitute</code></a>.</p>\n</dd></dl>\n\n</dd></dl>\n\n<aside class=\"version-note version-added\" data-version=\"3.1\" role=\"note\">\n<p class=\"version-note-title\">New in Django 3.1</p></aside>\n<p>If you need to customize error reports beyond filtering you may specify a\ncustom error reporter class by defining the\n<a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-DEFAULT_EXCEPTION_REPORTER\"><code class=\"xref std std-setting docutils literal notranslate\">DEFAULT_EXCEPTION_REPORTER</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>DEFAULT_EXCEPTION_REPORTER <span class=\"o\">=</span> <span class=\"s1\">&#39;path.to.your.CustomExceptionReporter&#39;</span>\n</code></pre></div>\n<p>The exception reporter is responsible for compiling the exception report data,\nand formatting it as text or HTML appropriately. (The exception reporter uses\n<a class=\"reference internal\" href=\"/id/3.1/ref/settings/#std-setting-DEFAULT_EXCEPTION_REPORTER_FILTER\"><code class=\"xref std std-setting docutils literal notranslate\">DEFAULT_EXCEPTION_REPORTER_FILTER</code></a> when preparing the exception\nreport data.)</p>\n<p>Your custom reporter class needs to inherit from\n<a class=\"reference internal\" href=\"#django.views.debug.ExceptionReporter\" title=\"django.views.debug.ExceptionReporter\"><code class=\"xref py py-class docutils literal notranslate\">django.views.debug.ExceptionReporter</code></a>.</p>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.views.debug.ExceptionReporter\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">ExceptionReporter</span><a class=\"heading-anchor\" href=\"#django.views.debug.ExceptionReporter\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.views.debug.ExceptionReporter.get_traceback_data\">\n<span class=\"sig-name descname\">get_traceback_data</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.debug.ExceptionReporter.get_traceback_data\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Return a dictionary containing traceback information.</p>\n<p>This is the main extension point for customizing exception reports, for\nexample:</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=\"nn\">django.views.debug</span> <span class=\"kn\">import</span> ExceptionReporter\n\n\n<span class=\"k\">class</span> <span class=\"nc\">CustomExceptionReporter</span><span class=\"p\">(</span>ExceptionReporter<span class=\"p\">):</span>\n    <span class=\"k\">def</span> <span class=\"nf\">get_traceback_data</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        data <span class=\"o\">=</span> <span class=\"nb\">super</span><span class=\"p\">()</span><span class=\"o\">.</span>get_traceback_data<span class=\"p\">()</span>\n        <span class=\"c1\"># ... remove/add something here ...</span>\n        <span class=\"k\">return</span> data\n</code></pre></div>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.views.debug.ExceptionReporter.get_traceback_html\">\n<span class=\"sig-name descname\">get_traceback_html</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.debug.ExceptionReporter.get_traceback_html\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Return HTML version of exception report.</p>\n<p>Used for HTML version of debug 500 HTTP error page.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.views.debug.ExceptionReporter.get_traceback_text\">\n<span class=\"sig-name descname\">get_traceback_text</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.debug.ExceptionReporter.get_traceback_text\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Return plain text version of exception report.</p>\n<p>Used for plain text version of debug 500 HTTP error page and email\nreports.</p>\n</dd></dl>\n\n</dd></dl>\n\n<p>As with the filter class, you may control which exception reporter class to use\nwithin any given view by setting the <code class=\"docutils literal notranslate\">HttpRequest</code>’s\n<code class=\"docutils literal notranslate\">exception_reporter_class</code> attribute:</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=\"nf\">my_view</span><span class=\"p\">(</span>request<span class=\"p\">):</span>\n    <span class=\"k\">if</span> request<span class=\"o\">.</span>user<span class=\"o\">.</span>is_authenticated<span class=\"p\">:</span>\n        request<span class=\"o\">.</span>exception_reporter_class <span class=\"o\">=</span> CustomExceptionReporter<span class=\"p\">()</span>\n    <span class=\"o\">...</span>\n</code></pre></div>\n<aside class=\"admonition admonition-seealso\" role=\"note\">\n<p class=\"admonition-title\">Lihat juga</p>\n<p>Anda dapat juga mengatur penyesuaian pelaporan kesalahan dengan menulis sebuah potongan penyesuaian dari <a class=\"reference internal\" href=\"/id/3.1/topics/http/middleware/#exception-middleware\"><span class=\"std std-ref\">exception middleware</span></a>. Jika anda melakukan menulis penyesuaian penanganan kesalahan, adalah ide bagus untuk meniru penanganan kesalahan siap pakai Django dan hanya laporan/catatan kesalahan jika setting:DEBUG adalah <code class=\"docutils literal notranslate\">False</code>.</p>\n</aside>\n</section>\n</section>","rootId":"error-reporting","toc":[{"title":"Surel laporan","anchor":"email-reports","children":[{"title":"Kesalahan peladen","anchor":"server-errors","children":[]},{"title":"kesalahan 404","anchor":"errors","children":[]}]},{"title":"Menyaring laporan kesalahan","anchor":"filtering-error-reports","children":[{"title":"Menyaring informasi rahasia","anchor":"filtering-sensitive-information","children":[]},{"title":"Penyesuaian laporan kesalahan","anchor":"custom-error-reports","children":[]}]}],"breadcrumbs":[{"docname":"howto/index","title":"Panduan \"Bagaimana\"","url":"/id/3.1/howto/"}],"prev":{"docname":"howto/upgrade-version","title":"Meningkatkan Django ke versi terbaru","url":"/id/3.1/howto/upgrade-version/"},"next":{"docname":"howto/initial-data","title":"Menyediakan data awal untuk model","url":"/id/3.1/howto/initial-data/"},"formats":{"html":"/id/3.1/howto/error-reporting/","markdown":"/id/3.1/howto/error-reporting.md","json":"/id/3.1/howto/error-reporting.json"},"source":"https://github.com/django/django/blob/stable/3.1.x/docs/howto/error-reporting.txt","official":"https://docs.djangoproject.com/id/3.1/howto/error-reporting/","inVersions":["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"],"inLocales":["en","zh-hans","fr","ja","id","pt-br","ko","es","el","pl"]}