{"title":"Middleware","version":"5.1","locale":"id","docname":"ref/middleware","url":"/id/5.1/ref/middleware/","canonical":"https://djangodocs.dev/id/5.1/ref/middleware/","summary":"Dokumen ini menjelaskan semua komponen middleware yang datang dengan Django. Untuk informasi pada bagaimana menggunakan mereka dan bagaimana menulis middleware anda…","html":"<span id=\"middleware\"></span><h1>Middleware<a class=\"heading-anchor\" href=\"#module-django.middleware\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>Dokumen ini menjelaskan semua komponen middleware yang datang dengan Django. Untuk informasi pada bagaimana menggunakan mereka dan bagaimana menulis middleware anda sendiri, lihat <a class=\"reference internal\" href=\"/id/5.1/topics/http/middleware/\"><span class=\"doc\">middleware usage guide</span></a>.</p>\n<section id=\"available-middleware\">\n<h2>Middleware tersedia<a class=\"heading-anchor\" href=\"#available-middleware\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"module-django.middleware.cache\">\n<span id=\"cache-middleware\"></span><h3>Middleware tembolok<a class=\"heading-anchor\" href=\"#module-django.middleware.cache\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.cache.UpdateCacheMiddleware\">\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\">UpdateCacheMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.cache.UpdateCacheMiddleware\"><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 class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.cache.FetchFromCacheMiddleware\">\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\">FetchFromCacheMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.cache.FetchFromCacheMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Enable the site-wide cache. If these are enabled, each Django-powered page will\nbe cached for as long as the <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-CACHE_MIDDLEWARE_SECONDS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CACHE_MIDDLEWARE_SECONDS</span></code></a> setting\ndefines. See the <a class=\"reference internal\" href=\"/id/5.1/topics/cache/\"><span class=\"doc\">cache documentation</span></a>.</p>\n</section>\n<section id=\"module-django.middleware.common\">\n<span id=\"common-middleware\"></span><h3>Middleware &quot;Umum&quot;<a class=\"heading-anchor\" href=\"#module-django.middleware.common\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.common.CommonMiddleware\">\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\">CommonMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.common.CommonMiddleware\"><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.middleware.common.CommonMiddleware.response_redirect_class\">\n<span class=\"sig-name descname\"><span class=\"pre\">response_redirect_class</span></span><a class=\"heading-anchor\" href=\"#django.middleware.common.CommonMiddleware.response_redirect_class\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Awalan pada <a class=\"reference internal\" href=\"/id/5.1/ref/request-response/#django.http.HttpResponsePermanentRedirect\" title=\"django.http.HttpResponsePermanentRedirect\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">HttpResponsePermanentRedirect</span></code></a>. Sub kelas <code class=\"docutils literal notranslate\"><span class=\"pre\">CommonMiddleware</span></code> dan menimpa atribut untuk menyesuaikan pengalihan diterbitkan oleh middleware.</p>\n</dd></dl>\n\n</dd></dl>\n\n<p>Tambah sedikit kenyamanan untuk perfeksionis:</p>\n<ul>\n<li><p>Larang akses ke agen pengguna dalam pengaturan <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-DISALLOWED_USER_AGENTS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DISALLOWED_USER_AGENTS</span></code></a>, yang harus berupa daftar dari obyek-obyek regular expression tersusun.</p></li>\n<li><p>Lakukan penulisan kembali URL pada pengaturan <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-APPEND_SLASH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">APPEND_SLASH</span></code></a> dan <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-PREPEND_WWW\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">PREPEND_WWW</span></code></a>.</p>\n<p>Jika <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-APPEND_SLASH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">APPEND_SLASH</span></code></a> adalah <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> dan URL permulaan tidak berakhir dengan garis miring, dan itu tidak ditemukan dalam URLconf, kemudian URL baru dibentuk dengan menambahkan sebuah garis miring pada akhiran. Jika URL baru ini ditemukan dalam URLconf, kemudian Django mengalihkan permintaan ke URL baru ini. Sebaliknya, URL permulaan diolah seperti biasa.</p>\n<p>Sebagai contoh, <code class=\"docutils literal notranslate\"><span class=\"pre\">foo.com/bar</span></code> akan dialihkan ke <code class=\"docutils literal notranslate\"><span class=\"pre\">foo.com/bar/</span></code> jika anda tidak memiliki pola URL sah untuk <code class=\"docutils literal notranslate\"><span class=\"pre\">foo.com/bar</span></code> tetapi <em>punya</em> pola sah untuk <code class=\"docutils literal notranslate\"><span class=\"pre\">foo.com/bar/</span></code>.</p>\n<p>Jika <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-PREPEND_WWW\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">PREPEND_WWW</span></code></a> adalah <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>, URL yang tidak memiliki awalan  &quot;www.&quot; akan dialihkan ke  URL sama dengan sebuah awalan &quot;www.&quot;</p>\n<p>Both of these options are meant to normalize URLs. The philosophy is that\neach URL should exist in one, and only one, place. Technically a URL\n<code class=\"docutils literal notranslate\"><span class=\"pre\">foo.com/bar</span></code> is distinct from <code class=\"docutils literal notranslate\"><span class=\"pre\">foo.com/bar/</span></code> -- a search-engine\nindexer would treat them as separate URLs -- so it's best practice to\nnormalize URLs.</p>\n<p>If necessary, individual views may be excluded from the <code class=\"docutils literal notranslate\"><span class=\"pre\">APPEND_SLASH</span></code>\nbehavior using the <a class=\"reference internal\" href=\"/id/5.1/topics/http/decorators/#django.views.decorators.common.no_append_slash\" title=\"django.views.decorators.common.no_append_slash\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">no_append_slash()</span></code></a>\ndecorator:</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.common</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">no_append_slash</span>\n\n\n<span class=\"nd\">@no_append_slash</span>\n<span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">sensitive_fbv</span><span class=\"p\">(</span><span class=\"n\">request</span><span class=\"p\">,</span> <span class=\"o\">*</span><span class=\"n\">args</span><span class=\"p\">,</span> <span class=\"o\">**</span><span class=\"n\">kwargs</span><span class=\"p\">):</span>\n<span class=\"w\">    </span><span class=\"sd\">&quot;&quot;&quot;View to be excluded from APPEND_SLASH.&quot;&quot;&quot;</span>\n    <span class=\"k\">return</span> <span class=\"n\">HttpResponse</span><span class=\"p\">()</span>\n</code></pre></div>\n</li>\n<li><p>Setel kepala <code class=\"docutils literal notranslate\"><span class=\"pre\">Content-Length</span></code> untuk tanggapan bukan-aliran.</p></li>\n</ul>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.common.BrokenLinkEmailsMiddleware\">\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\">BrokenLinkEmailsMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.common.BrokenLinkEmailsMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<ul class=\"simple\">\n<li><p>Mengirim surel pemberitahuan tautan rusak pada <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-MANAGERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MANAGERS</span></code></a> (see <a class=\"reference internal\" href=\"/id/5.1/howto/error-reporting/\"><span class=\"doc\">Bagaimana mengelola pelaporan kesalahan</span></a>).</p></li>\n</ul>\n</section>\n<section id=\"module-django.middleware.gzip\">\n<span id=\"gzip-middleware\"></span><h3>Middleware GZip<a class=\"heading-anchor\" href=\"#module-django.middleware.gzip\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.gzip.GZipMiddleware\">\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\">GZipMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.gzip.GZipMiddleware\"><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.middleware.gzip.GZipMiddleware.max_random_bytes\">\n<span class=\"sig-name descname\"><span class=\"pre\">max_random_bytes</span></span><a class=\"heading-anchor\" href=\"#django.middleware.gzip.GZipMiddleware.max_random_bytes\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Defaults to 100. Subclass <code class=\"docutils literal notranslate\"><span class=\"pre\">GZipMiddleware</span></code> and override the attribute\nto change the maximum number of random bytes that is included with\ncompressed responses.</p>\n</dd></dl>\n\n</dd></dl>\n\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Catatan</p>\n<p>Security researchers revealed that when compression techniques (including\n<code class=\"docutils literal notranslate\"><span class=\"pre\">GZipMiddleware</span></code>) are used on a website, the site may become exposed to a\nnumber of possible attacks.</p>\n<p>To mitigate attacks, Django implements a technique called <em>Heal The Breach\n(HTB)</em>. It adds up to 100 bytes (see\n<a class=\"reference internal\" href=\"#django.middleware.gzip.GZipMiddleware.max_random_bytes\" title=\"django.middleware.gzip.GZipMiddleware.max_random_bytes\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">max_random_bytes</span></code></a>) of random bytes to each response\nto make the attacks less effective.</p>\n<p>For more details, see the <a class=\"reference external\" href=\"https://www.breachattack.com/resources/BREACH%20-%20SSL,%20gone%20in%2030%20seconds.pdf\">BREACH paper (PDF)</a>, <a class=\"reference external\" href=\"https://www.breachattack.com/\">breachattack.com</a>, and\nthe <a class=\"reference external\" href=\"https://ieeexplore.ieee.org/document/9754554\">Heal The Breach (HTB) paper</a>.</p>\n</aside>\n<p>The <code class=\"docutils literal notranslate\"><span class=\"pre\">django.middleware.gzip.GZipMiddleware</span></code> compresses content for browsers\nthat understand GZip compression (all modern browsers).</p>\n<p>Middleware ini harus ditempatkan sebelum middleware lain apapun yang butuh membaca atau menulis tanggapan badan sehingga pemampatan terjadi kemudian.</p>\n<p>Itu TIDAK akan memampatkan isi jika apapun dari berikut adalah true:</p>\n<ul class=\"simple\">\n<li><p>Isi badan kurang dari panjang 200 byte.</p></li>\n<li><p>Tanggapan telah menyetel kepala <code class=\"docutils literal notranslate\"><span class=\"pre\">Content-Encoding</span></code>.</p></li>\n<li><p>Permintaan (peramban) belum mengirim sebuah kepala <code class=\"docutils literal notranslate\"><span class=\"pre\">Accept-Encoding</span></code> mengandung <code class=\"docutils literal notranslate\"><span class=\"pre\">gzip</span></code>.</p></li>\n</ul>\n<p>If the response has an <code class=\"docutils literal notranslate\"><span class=\"pre\">ETag</span></code> header, the ETag is made weak to comply with\n<span class=\"target\" id=\"index-0\"></span><a class=\"rfc reference external\" href=\"https://datatracker.ietf.org/doc/html/rfc9110.html#section-8.8.1\"><strong>RFC 9110 Section 8.8.1</strong></a>.</p>\n<p>Anda dapat memberlakukan pemampatan GZip pada tampilan sendiri menggunakan penghias <a class=\"reference internal\" href=\"/id/5.1/topics/http/decorators/#django.views.decorators.gzip.gzip_page\" title=\"django.views.decorators.gzip.gzip_page\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">gzip_page()</span></code></a>.</p>\n</section>\n<section id=\"module-django.middleware.http\">\n<span id=\"conditional-get-middleware\"></span><h3>Middleware GET bersyarat<a class=\"heading-anchor\" href=\"#module-django.middleware.http\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.http.ConditionalGetMiddleware\">\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\">ConditionalGetMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.http.ConditionalGetMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Menangani tindakan GET bersyarat. Jika tanggapan tidak memiliki sebuah kepala <code class=\"docutils literal notranslate\"><span class=\"pre\">ETag</span></code>, middleware menambahkan satu jika dibutuhkan. Jika tanggapan mempunyai sebuah kepala <code class=\"docutils literal notranslate\"><span class=\"pre\">ETag</span></code> atau <code class=\"docutils literal notranslate\"><span class=\"pre\">Last-Modified</span></code>, dan permintaan memiliki <code class=\"docutils literal notranslate\"><span class=\"pre\">If-None-Match</span></code> atau <code class=\"docutils literal notranslate\"><span class=\"pre\">If-Modified-Since</span></code>, tanggapan diganti oleh sebuah <a class=\"reference internal\" href=\"/id/5.1/ref/request-response/#django.http.HttpResponseNotModified\" title=\"django.http.HttpResponseNotModified\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">HttpResponseNotModified</span></code></a>.</p>\n</section>\n<section id=\"module-django.middleware.locale\">\n<span id=\"locale-middleware\"></span><h3>Middleware lokal<a class=\"heading-anchor\" href=\"#module-django.middleware.locale\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.locale.LocaleMiddleware\">\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\">LocaleMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.locale.LocaleMiddleware\"><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.middleware.locale.LocaleMiddleware.response_redirect_class\">\n<span class=\"sig-name descname\"><span class=\"pre\">response_redirect_class</span></span><a class=\"heading-anchor\" href=\"#django.middleware.locale.LocaleMiddleware.response_redirect_class\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Awalan pada <a class=\"reference internal\" href=\"/id/5.1/ref/request-response/#django.http.HttpResponseRedirect\" title=\"django.http.HttpResponseRedirect\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">HttpResponseRedirect</span></code></a>. Sub kelas <code class=\"docutils literal notranslate\"><span class=\"pre\">LocaleMiddleware</span></code> dan menimpa atribut untuk menyesuaikan pengalihan diterbitkan oleh middleware.</p>\n</dd></dl>\n\n</dd></dl>\n\n<p>Enables language selection based on data from the request. It customizes\ncontent for each user. See the <a class=\"reference internal\" href=\"/id/5.1/topics/i18n/translation/\"><span class=\"doc\">internationalization documentation</span></a>.</p>\n</section>\n<section id=\"module-django.contrib.messages.middleware\">\n<span id=\"message-middleware\"></span><h3>Middleware pesan<a class=\"heading-anchor\" href=\"#module-django.contrib.messages.middleware\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.messages.middleware.MessageMiddleware\">\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\">MessageMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.contrib.messages.middleware.MessageMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Enables cookie- and session-based message support. See the\n<a class=\"reference internal\" href=\"/id/5.1/ref/contrib/messages/\"><span class=\"doc\">messages documentation</span></a>.</p>\n</section>\n<section id=\"module-django.middleware.security\">\n<span id=\"id1\"></span><span id=\"security-middleware\"></span><h3>Middleware keamanan<a class=\"heading-anchor\" href=\"#module-django.middleware.security\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Peringatan</p>\n<p>If your deployment situation allows, it's usually a good idea to have your\nfront-end web server perform the functionality provided by the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code>. That way, if there are requests that aren't served\nby Django (such as static media or user-uploaded files), they will have\nthe same protections as requests to your Django application.</p>\n</aside>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.security.SecurityMiddleware\">\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\">SecurityMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.security.SecurityMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">django.middleware.security.SecurityMiddleware</span></code> menyediakan beberapa peningkatan keamanan pada siklus permintaan/tanggapan. Setiap satu dapat berdiri sendiri mengadakan atau mentiadakan dengan sebuah pengaturan.</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_CONTENT_TYPE_NOSNIFF\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_CONTENT_TYPE_NOSNIFF</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_CROSS_ORIGIN_OPENER_POLICY\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_CROSS_ORIGIN_OPENER_POLICY</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_HSTS_INCLUDE_SUBDOMAINS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_INCLUDE_SUBDOMAINS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_HSTS_PRELOAD\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_PRELOAD</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_HSTS_SECONDS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_SECONDS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_REDIRECT_EXEMPT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_REDIRECT_EXEMPT</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_REFERRER_POLICY\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_REFERRER_POLICY</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_SSL_HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_SSL_HOST</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_SSL_REDIRECT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_SSL_REDIRECT</span></code></a></p></li>\n</ul>\n<section id=\"http-strict-transport-security\">\n<span id=\"id2\"></span><h4>HTTP Strict Transport Security<a class=\"heading-anchor\" href=\"#http-strict-transport-security\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>For sites that should only be accessed over HTTPS, you can instruct modern\nbrowsers to refuse to connect to your domain name via an insecure connection\n(for a given period of time) by setting the <a class=\"reference external\" href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security\">&quot;Strict-Transport-Security&quot;\nheader</a>. This reduces your exposure to some SSL-stripping man-in-the-middle\n(MITM) attacks.</p>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code> akan menyetel kepala ini untuk anda pada semua tanggapan HTTPS jika anda mensetel pengaturan <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_HSTS_SECONDS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_SECONDS</span></code></a> pada nilai integer bukan-nol.</p>\n<p>When enabling HSTS, it's a good idea to first use a small value for testing,\nfor example, <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_HSTS_SECONDS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_SECONDS</span> <span class=\"pre\">=</span> <span class=\"pre\">3600</span></code></a> for one\nhour. Each time a web browser sees the HSTS header from your site, it will\nrefuse to communicate non-securely (using HTTP) with your domain for the given\nperiod of time. Once you confirm that all assets are served securely on your\nsite (i.e. HSTS didn't break anything), it's a good idea to increase this value\nso that infrequent visitors will be protected (31536000 seconds, i.e. 1 year,\nis common).</p>\n<p>Additionally, if you set the <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_HSTS_INCLUDE_SUBDOMAINS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_INCLUDE_SUBDOMAINS</span></code></a> setting\nto <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code> will add the <code class=\"docutils literal notranslate\"><span class=\"pre\">includeSubDomains</span></code> directive\nto the <code class=\"docutils literal notranslate\"><span class=\"pre\">Strict-Transport-Security</span></code> header. This is recommended (assuming all\nsubdomains are served exclusively using HTTPS), otherwise your site may still\nbe vulnerable via an insecure connection to a subdomain.</p>\n<p>Jika anda berharap mengajukan situs anda ke <a class=\"reference external\" href=\"https://hstspreload.org/\">browser preload list</a>, setel pengaturan <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_HSTS_PRELOAD\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_PRELOAD</span></code></a> menjadi <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>. Itu menambahkan <code class=\"docutils literal notranslate\"><span class=\"pre\">preload</span></code> menunjuk ke kepala <code class=\"docutils literal notranslate\"><span class=\"pre\">Strict-Transport-Security</span></code>.</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Peringatan</p>\n<p>The HSTS policy applies to your entire domain, not just the URL of the\nresponse that you set the header on. Therefore, you should only use it if\nyour entire domain is served via HTTPS only.</p>\n<p>Browsers properly respecting the HSTS header will refuse to allow users to\nbypass warnings and connect to a site with an expired, self-signed, or\notherwise invalid SSL certificate. If you use HSTS, make sure your\ncertificates are in good shape and stay that way!</p>\n</aside>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Catatan</p>\n<p>If you are deployed behind a load-balancer or reverse-proxy server, and the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">Strict-Transport-Security</span></code> header is not being added to your responses,\nit may be because Django doesn't realize that it's on a secure connection;\nyou may need to set the <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_PROXY_SSL_HEADER\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_PROXY_SSL_HEADER</span></code></a> setting.</p>\n</aside>\n</section>\n<section id=\"referrer-policy\">\n<span id=\"id4\"></span><h4>Referrer Policy<a class=\"heading-anchor\" href=\"#referrer-policy\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Browsers use <a class=\"reference external\" href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer\">the Referer header</a> as a way to send information to a site\nabout how users got there. When a user clicks a link, the browser will send the\nfull URL of the linking page as the referrer. While this can be useful for some\npurposes -- like figuring out who's linking to your site -- it also can cause\nprivacy concerns by informing one site that a user was visiting another site.</p>\n<p>Some browsers have the ability to accept hints about whether they should send\nthe HTTP <code class=\"docutils literal notranslate\"><span class=\"pre\">Referer</span></code> header when a user clicks a link; this hint is provided\nvia <a class=\"reference external\" href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy\">the Referrer-Policy header</a>. This header can suggest any of three\nbehaviors to browsers:</p>\n<ul class=\"simple\">\n<li><p>Full URL: send the entire URL in the <code class=\"docutils literal notranslate\"><span class=\"pre\">Referer</span></code> header. For example, if the\nuser is visiting <code class=\"docutils literal notranslate\"><span class=\"pre\">https://example.com/page.html</span></code>, the <code class=\"docutils literal notranslate\"><span class=\"pre\">Referer</span></code> header\nwould contain <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;https://example.com/page.html&quot;</span></code>.</p></li>\n<li><p>Origin only: send only the &quot;origin&quot; in the referrer. The origin consists of\nthe scheme, host and (optionally) port number. For example, if the user is\nvisiting <code class=\"docutils literal notranslate\"><span class=\"pre\">https://example.com/page.html</span></code>, the origin would be\n<code class=\"docutils literal notranslate\"><span class=\"pre\">https://example.com/</span></code>.</p></li>\n<li><p>No referrer: do not send a <code class=\"docutils literal notranslate\"><span class=\"pre\">Referer</span></code> header at all.</p></li>\n</ul>\n<p>There are two types of conditions this header can tell a browser to watch out\nfor:</p>\n<ul class=\"simple\">\n<li><p>Same-origin versus cross-origin: a link from <code class=\"docutils literal notranslate\"><span class=\"pre\">https://example.com/1.html</span></code>\nto <code class=\"docutils literal notranslate\"><span class=\"pre\">https://example.com/2.html</span></code> is same-origin. A link from\n<code class=\"docutils literal notranslate\"><span class=\"pre\">https://example.com/page.html</span></code> to <code class=\"docutils literal notranslate\"><span class=\"pre\">https://not.example.com/page.html</span></code> is\ncross-origin.</p></li>\n<li><p>Protocol downgrade: a downgrade occurs if the page containing the link is\nserved via HTTPS, but the page being linked to is not served via HTTPS.</p></li>\n</ul>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Peringatan</p>\n<p>When your site is served via HTTPS, <a class=\"reference internal\" href=\"/id/5.1/ref/csrf/#how-csrf-works\"><span class=\"std std-ref\">Django's CSRF protection system</span></a> requires the <code class=\"docutils literal notranslate\"><span class=\"pre\">Referer</span></code> header to be present, so\ncompletely disabling the <code class=\"docutils literal notranslate\"><span class=\"pre\">Referer</span></code> header will interfere with CSRF\nprotection. To gain most of the benefits of disabling <code class=\"docutils literal notranslate\"><span class=\"pre\">Referer</span></code> headers\nwhile also keeping CSRF protection, consider enabling only same-origin\nreferrers.</p>\n</aside>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code> can set the <code class=\"docutils literal notranslate\"><span class=\"pre\">Referrer-Policy</span></code> header for you, based on\nthe <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_REFERRER_POLICY\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_REFERRER_POLICY</span></code></a> setting (note spelling: browsers send a\n<code class=\"docutils literal notranslate\"><span class=\"pre\">Referer</span></code> header when a user clicks a link, but the header instructing a\nbrowser whether to do so is spelled <code class=\"docutils literal notranslate\"><span class=\"pre\">Referrer-Policy</span></code>). The valid values for\nthis setting are:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">no-referrer</span></code></dt><dd><p>Instructs the browser to send no referrer for links clicked on this site.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">no-referrer-when-downgrade</span></code></dt><dd><p>Instructs the browser to send a full URL as the referrer, but only when no\nprotocol downgrade occurs.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">origin</span></code></dt><dd><p>Instructs the browser to send only the origin, not the full URL, as the\nreferrer.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">origin-when-cross-origin</span></code></dt><dd><p>Instructs the browser to send the full URL as the referrer for same-origin\nlinks, and only the origin for cross-origin links.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">same-origin</span></code></dt><dd><p>Instructs the browser to send a full URL, but only for same-origin links. No\nreferrer will be sent for cross-origin links.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">strict-origin</span></code></dt><dd><p>Instructs the browser to send only the origin, not the full URL, and to send\nno referrer when a protocol downgrade occurs.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">strict-origin-when-cross-origin</span></code></dt><dd><p>Instructs the browser to send the full URL when the link is same-origin and\nno protocol downgrade occurs; send only the origin when the link is\ncross-origin and no protocol downgrade occurs; and no referrer when a\nprotocol downgrade occurs.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">unsafe-url</span></code></dt><dd><p>Instructs the browser to always send the full URL as the referrer.</p>\n</dd>\n</dl>\n<aside class=\"admonition-unknown-policy-values admonition\">\n<p class=\"admonition-title\">Unknown Policy Values</p>\n<p>Where a policy value is <a class=\"reference external\" href=\"https://w3c.github.io/webappsec-referrer-policy/#unknown-policy-values\">unknown</a> by a user agent, it is possible to\nspecify multiple policy values to provide a fallback. The last specified\nvalue that is understood takes precedence. To support this, an iterable or\ncomma-separated string can be used with <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_REFERRER_POLICY\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_REFERRER_POLICY</span></code></a>.</p>\n</aside>\n</section>\n<section id=\"cross-origin-opener-policy\">\n<span id=\"id8\"></span><h4>Cross-Origin Opener Policy<a class=\"heading-anchor\" href=\"#cross-origin-opener-policy\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Some browsers have the ability to isolate top-level windows from other\ndocuments by putting them in a separate browsing context group based on the\nvalue of the <a class=\"reference external\" href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy\">Cross-Origin Opener Policy</a> (COOP) header. If a document that\nis isolated in this way opens a cross-origin popup window, the popup’s\n<code class=\"docutils literal notranslate\"><span class=\"pre\">window.opener</span></code> property will be <code class=\"docutils literal notranslate\"><span class=\"pre\">null</span></code>. Isolating windows using COOP is a\ndefense-in-depth protection against cross-origin attacks, especially those like\nSpectre which allowed exfiltration of data loaded into a shared browsing\ncontext.</p>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code> can set the <code class=\"docutils literal notranslate\"><span class=\"pre\">Cross-Origin-Opener-Policy</span></code> header for\nyou, based on the <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_CROSS_ORIGIN_OPENER_POLICY\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_CROSS_ORIGIN_OPENER_POLICY</span></code></a> setting. The\nvalid values for this setting are:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">same-origin</span></code></dt><dd><p>Isolates the browsing context exclusively to same-origin documents.\nCross-origin documents are not loaded in the same browsing context. This\nis the default and most secure option.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">same-origin-allow-popups</span></code></dt><dd><p>Isolates the browsing context to same-origin documents or those which\neither don't set COOP or which opt out of isolation by setting a COOP of\n<code class=\"docutils literal notranslate\"><span class=\"pre\">unsafe-none</span></code>.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">unsafe-none</span></code></dt><dd><p>Allows the document to be added to its opener's browsing context group\nunless the opener itself has a COOP of <code class=\"docutils literal notranslate\"><span class=\"pre\">same-origin</span></code> or\n<code class=\"docutils literal notranslate\"><span class=\"pre\">same-origin-allow-popups</span></code>.</p>\n</dd>\n</dl>\n</section>\n<section id=\"x-content-type-options-nosniff\">\n<span id=\"x-content-type-options\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">X-Content-Type-Options:</span> <span class=\"pre\">nosniff</span></code><a class=\"heading-anchor\" href=\"#x-content-type-options-nosniff\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Some browsers will try to guess the content types of the assets that they\nfetch, overriding the <code class=\"docutils literal notranslate\"><span class=\"pre\">Content-Type</span></code> header. While this can help display\nsites with improperly configured servers, it can also pose a security\nrisk.</p>\n<p>If your site serves user-uploaded files, a malicious user could upload a\nspecially-crafted file that would be interpreted as HTML or JavaScript by\nthe browser when you expected it to be something harmless.</p>\n<p>To prevent the browser from guessing the content type and force it to\nalways use the type provided in the <code class=\"docutils literal notranslate\"><span class=\"pre\">Content-Type</span></code> header, you can pass\nthe <a class=\"reference external\" href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options\">X-Content-Type-Options: nosniff</a> header.  <code class=\"docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code> will\ndo this for all responses if the <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_CONTENT_TYPE_NOSNIFF\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_CONTENT_TYPE_NOSNIFF</span></code></a> setting\nis <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>.</p>\n<p>Note that in most deployment situations where Django isn't involved in serving\nuser-uploaded files, this setting won't help you. For example, if your\n<a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-MEDIA_URL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MEDIA_URL</span></code></a> is served directly by your front-end web server (nginx,\nApache, etc.) then you'd want to set this header there. On the other hand, if\nyou are using Django to do something like require authorization in order to\ndownload files and you cannot set the header using your web server, this\nsetting will be useful.</p>\n</section>\n<section id=\"ssl-redirect\">\n<span id=\"id11\"></span><h4>Pengalihan SSL<a class=\"heading-anchor\" href=\"#ssl-redirect\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>If your site offers both HTTP and HTTPS connections, most users will end up\nwith an unsecured connection by default. For best security, you should redirect\nall HTTP connections to HTTPS.</p>\n<p>If you set the <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_SSL_REDIRECT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_SSL_REDIRECT</span></code></a> setting to True,\n<code class=\"docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code> will permanently (HTTP 301) redirect all HTTP\nconnections to HTTPS.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Catatan</p>\n<p>For performance reasons, it's preferable to do these redirects outside of\nDjango, in a front-end load balancer or reverse-proxy server such as\n<a class=\"reference external\" href=\"https://nginx.org/\">nginx</a>. <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_SSL_REDIRECT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_SSL_REDIRECT</span></code></a> is intended for the deployment\nsituations where this isn't an option.</p>\n</aside>\n<p>If the <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_SSL_HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_SSL_HOST</span></code></a> setting has a value, all redirects will be\nsent to that host instead of the originally-requested host.</p>\n<p>If there are a few pages on your site that should be available over HTTP, and\nnot redirected to HTTPS, you can list regular expressions to match those URLs\nin the <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_REDIRECT_EXEMPT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_REDIRECT_EXEMPT</span></code></a> setting.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Catatan</p>\n<p>If you are deployed behind a load-balancer or reverse-proxy server and\nDjango can't seem to tell when a request actually is already secure, you\nmay need to set the <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-SECURE_PROXY_SSL_HEADER\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_PROXY_SSL_HEADER</span></code></a> setting.</p>\n</aside>\n</section>\n</section>\n<section id=\"module-django.contrib.sessions.middleware\">\n<span id=\"session-middleware\"></span><h3>Middleware sesi<a class=\"heading-anchor\" href=\"#module-django.contrib.sessions.middleware\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.sessions.middleware.SessionMiddleware\">\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\">SessionMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.contrib.sessions.middleware.SessionMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Mengadakan dukungan sesi. Lihat <a class=\"reference internal\" href=\"/id/5.1/topics/http/sessions/\"><span class=\"doc\">session documentation</span></a>.</p>\n</section>\n<section id=\"module-django.contrib.sites.middleware\">\n<span id=\"site-middleware\"></span><h3>Situs middleware<a class=\"heading-anchor\" href=\"#module-django.contrib.sites.middleware\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.sites.middleware.CurrentSiteMiddleware\">\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\">CurrentSiteMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.contrib.sites.middleware.CurrentSiteMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Adds the <code class=\"docutils literal notranslate\"><span class=\"pre\">site</span></code> attribute representing the current site to every incoming\n<code class=\"docutils literal notranslate\"><span class=\"pre\">HttpRequest</span></code> object. See the <a class=\"reference internal\" href=\"/id/5.1/ref/contrib/sites/#site-middleware\"><span class=\"std std-ref\">sites documentation</span></a>.</p>\n</section>\n<section id=\"module-django.contrib.auth.middleware\">\n<span id=\"authentication-middleware\"></span><h3>Middleware otentifikasi<a class=\"heading-anchor\" href=\"#module-django.contrib.auth.middleware\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.auth.middleware.AuthenticationMiddleware\">\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\">AuthenticationMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.contrib.auth.middleware.AuthenticationMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Adds the <code class=\"docutils literal notranslate\"><span class=\"pre\">user</span></code> attribute, representing the currently-logged-in user, to\nevery incoming <code class=\"docutils literal notranslate\"><span class=\"pre\">HttpRequest</span></code> object. See <a class=\"reference internal\" href=\"/id/5.1/topics/auth/default/#auth-web-requests\"><span class=\"std std-ref\">Authentication in web requests</span></a>.</p>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.auth.middleware.LoginRequiredMiddleware\">\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\">LoginRequiredMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.contrib.auth.middleware.LoginRequiredMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Subclass the middleware and override the following attributes and methods\nto customize behavior for unauthenticated requests.</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.auth.middleware.LoginRequiredMiddleware.redirect_field_name\">\n<span class=\"sig-name descname\"><span class=\"pre\">redirect_field_name</span></span><a class=\"heading-anchor\" href=\"#django.contrib.auth.middleware.LoginRequiredMiddleware.redirect_field_name\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Defaults to <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;next&quot;</span></code>.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.auth.middleware.LoginRequiredMiddleware.get_login_url\">\n<span class=\"sig-name descname\"><span class=\"pre\">get_login_url</span></span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.contrib.auth.middleware.LoginRequiredMiddleware.get_login_url\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns the URL that unauthenticated requests will be redirected to. This\nresult is either the <code class=\"docutils literal notranslate\"><span class=\"pre\">login_url</span></code> set on the\n<a class=\"reference internal\" href=\"/id/5.1/topics/auth/default/#django.contrib.auth.decorators.login_required\" title=\"django.contrib.auth.decorators.login_required\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">login_required()</span></code></a> decorator (if not\n<code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>), or <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-LOGIN_URL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">settings.LOGIN_URL</span></code></a>.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.auth.middleware.LoginRequiredMiddleware.get_redirect_field_name\">\n<span class=\"sig-name descname\"><span class=\"pre\">get_redirect_field_name</span></span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.contrib.auth.middleware.LoginRequiredMiddleware.get_redirect_field_name\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns the name of the query parameter that contains the URL the user\nshould be redirected to after a successful login. This result is either\nthe <code class=\"docutils literal notranslate\"><span class=\"pre\">redirect_field_name</span></code> set on the\n<a class=\"reference internal\" href=\"/id/5.1/topics/auth/default/#django.contrib.auth.decorators.login_required\" title=\"django.contrib.auth.decorators.login_required\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">login_required()</span></code></a> decorator (if not\n<code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>), or <a class=\"reference internal\" href=\"#django.contrib.auth.middleware.LoginRequiredMiddleware.redirect_field_name\" title=\"django.contrib.auth.middleware.LoginRequiredMiddleware.redirect_field_name\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">redirect_field_name</span></code></a>. If <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code> is returned, a query\nparameter won't be added.</p>\n</dd></dl>\n\n</dd></dl>\n\n<aside class=\"version-note version-added\" data-version=\"5.1\">\n<p class=\"version-note-title\">New in Django 5.1</p></aside>\n<p>Redirects all unauthenticated requests to a login page, except for views\nexcluded with <a class=\"reference internal\" href=\"/id/5.1/topics/auth/default/#django.contrib.auth.decorators.login_not_required\" title=\"django.contrib.auth.decorators.login_not_required\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">login_not_required()</span></code></a>. The\nlogin page defaults to <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-LOGIN_URL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">settings.LOGIN_URL</span></code></a>, but can be\ncustomized.</p>\n<p>Enable this middleware by adding it to the <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-MIDDLEWARE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MIDDLEWARE</span></code></a> setting\n<strong>after</strong> <a class=\"reference internal\" href=\"#django.contrib.auth.middleware.AuthenticationMiddleware\" title=\"django.contrib.auth.middleware.AuthenticationMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AuthenticationMiddleware</span></code></a>:</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\">MIDDLEWARE</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"s2\">&quot;...&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;django.contrib.auth.middleware.AuthenticationMiddleware&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;django.contrib.auth.middleware.LoginRequiredMiddleware&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;...&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>Make a view public, allowing unauthenticated requests, with\n<a class=\"reference internal\" href=\"/id/5.1/topics/auth/default/#django.contrib.auth.decorators.login_not_required\" title=\"django.contrib.auth.decorators.login_not_required\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">login_not_required()</span></code></a>. 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\">from</span><span class=\"w\"> </span><span class=\"nn\">django.contrib.auth.decorators</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">login_not_required</span>\n\n\n<span class=\"nd\">@login_not_required</span>\n<span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">contact_us</span><span class=\"p\">(</span><span class=\"n\">request</span><span class=\"p\">):</span> <span class=\"o\">...</span>\n</code></pre></div>\n<p>Customize the login URL or field name for authenticated views with the\n<a class=\"reference internal\" href=\"/id/5.1/topics/auth/default/#django.contrib.auth.decorators.login_required\" title=\"django.contrib.auth.decorators.login_required\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">login_required()</span></code></a> decorator to set\n<code class=\"docutils literal notranslate\"><span class=\"pre\">login_url</span></code> or <code class=\"docutils literal notranslate\"><span class=\"pre\">redirect_field_name</span></code> respectively. 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\">from</span><span class=\"w\"> </span><span class=\"nn\">django.contrib.auth.decorators</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">login_required</span>\n<span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.utils.decorators</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">method_decorator</span>\n<span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.views.generic</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">View</span>\n\n\n<span class=\"nd\">@login_required</span><span class=\"p\">(</span><span class=\"n\">login_url</span><span class=\"o\">=</span><span class=\"s2\">&quot;/books/login/&quot;</span><span class=\"p\">,</span> <span class=\"n\">redirect_field_name</span><span class=\"o\">=</span><span class=\"s2\">&quot;redirect_to&quot;</span><span class=\"p\">)</span>\n<span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">book_dashboard</span><span class=\"p\">(</span><span class=\"n\">request</span><span class=\"p\">):</span> <span class=\"o\">...</span>\n\n\n<span class=\"nd\">@method_decorator</span><span class=\"p\">(</span>\n    <span class=\"n\">login_required</span><span class=\"p\">(</span><span class=\"n\">login_url</span><span class=\"o\">=</span><span class=\"s2\">&quot;/books/login/&quot;</span><span class=\"p\">,</span> <span class=\"n\">redirect_field_name</span><span class=\"o\">=</span><span class=\"s2\">&quot;redirect_to&quot;</span><span class=\"p\">),</span>\n    <span class=\"n\">name</span><span class=\"o\">=</span><span class=\"s2\">&quot;dispatch&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">)</span>\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">BookMetrics</span><span class=\"p\">(</span><span class=\"n\">View</span><span class=\"p\">):</span>\n    <span class=\"k\">pass</span>\n</code></pre></div>\n<aside class=\"admonition-ensure-that-your-login-view-does-not-require-a-login admonition\">\n<p class=\"admonition-title\">Ensure that your login view does not require a login.</p>\n<p>To prevent infinite redirects, ensure you have\n<a class=\"reference internal\" href=\"/id/5.1/topics/auth/default/#disable-login-required-middleware-for-views\"><span class=\"std std-ref\">enabled unauthenticated requests</span></a> to your login view.</p>\n</aside>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.auth.middleware.RemoteUserMiddleware\">\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\">RemoteUserMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.contrib.auth.middleware.RemoteUserMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Middleware for utilizing web server provided authentication. See\n<a class=\"reference internal\" href=\"/id/5.1/howto/auth-remote-user/\"><span class=\"doc\">Bagaimana mengotentikasi menggunakan REMOTE_USER</span></a> for usage details.</p>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.auth.middleware.PersistentRemoteUserMiddleware\">\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\">PersistentRemoteUserMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.contrib.auth.middleware.PersistentRemoteUserMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Middleware for utilizing web server provided authentication when enabled only\non the login page. See <a class=\"reference internal\" href=\"/id/5.1/howto/auth-remote-user/#persistent-remote-user-middleware-howto\"><span class=\"std std-ref\">Menggunakan REMOTE_USER hanya pada halaman masuk</span></a> for usage\ndetails.</p>\n</section>\n<section id=\"csrf-protection-middleware\">\n<h3>Middleware perlindungan CSRF<a class=\"heading-anchor\" href=\"#csrf-protection-middleware\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.csrf.CsrfViewMiddleware\">\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\">CsrfViewMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.csrf.CsrfViewMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Adds protection against Cross Site Request Forgeries by adding hidden form\nfields to POST forms and checking requests for the correct value. See the\n<a class=\"reference internal\" href=\"/id/5.1/ref/csrf/\"><span class=\"doc\">Cross Site Request Forgery protection documentation</span></a>.</p>\n</section>\n<section id=\"x-frame-options-middleware\">\n<h3>Middleware <code class=\"docutils literal notranslate\"><span class=\"pre\">X-Frame-Options</span></code><a class=\"heading-anchor\" href=\"#x-frame-options-middleware\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.clickjacking.XFrameOptionsMiddleware\">\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\">XFrameOptionsMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.clickjacking.XFrameOptionsMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Simple <a class=\"reference internal\" href=\"/id/5.1/ref/clickjacking/\"><span class=\"doc\">clickjacking protection via the X-Frame-Options header</span></a>.</p>\n</section>\n</section>\n<section id=\"middleware-ordering\">\n<span id=\"id12\"></span><h2>Pengurutan middleware<a class=\"heading-anchor\" href=\"#middleware-ordering\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Disini adalah beberapa petunjuk tentang pengurutan beragam kelas-kelas middleware Django:</p>\n<ol class=\"arabic\">\n<li><p><a class=\"reference internal\" href=\"#django.middleware.security.SecurityMiddleware\" title=\"django.middleware.security.SecurityMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code></a></p>\n<p>It should go near the top of the list if you're going to turn on the SSL\nredirect as that avoids running through a bunch of other unnecessary\nmiddleware.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.middleware.cache.UpdateCacheMiddleware\" title=\"django.middleware.cache.UpdateCacheMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">UpdateCacheMiddleware</span></code></a></p>\n<p>Sebelum itu yang merubah kepala <code class=\"docutils literal notranslate\"><span class=\"pre\">Vary</span></code> (<code class=\"docutils literal notranslate\"><span class=\"pre\">SessionMiddleware</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">GZipMiddleware</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">LocaleMiddleware</span></code>).</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.middleware.gzip.GZipMiddleware\" title=\"django.middleware.gzip.GZipMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">GZipMiddleware</span></code></a></p>\n<p>Sebelum middleware apapun yang mungkin merubah atau menggunakan tanggapan badan.</p>\n<p>Setelah <code class=\"docutils literal notranslate\"><span class=\"pre\">UpdateCacheMiddleware</span></code>: Rubah kepala <code class=\"docutils literal notranslate\"><span class=\"pre\">Vary</span></code>.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.contrib.sessions.middleware.SessionMiddleware\" title=\"django.contrib.sessions.middleware.SessionMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">SessionMiddleware</span></code></a></p>\n<p>Before any middleware that may raise an exception to trigger an error\nview (such as <a class=\"reference internal\" href=\"/id/5.1/ref/exceptions/#django.core.exceptions.PermissionDenied\" title=\"django.core.exceptions.PermissionDenied\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">PermissionDenied</span></code></a>) if you're\nusing <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-CSRF_USE_SESSIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CSRF_USE_SESSIONS</span></code></a>.</p>\n<p>Setelah <code class=\"docutils literal notranslate\"><span class=\"pre\">UpdateCacheMiddleware</span></code>: Rubah kepala <code class=\"docutils literal notranslate\"><span class=\"pre\">Vary</span></code>.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.middleware.http.ConditionalGetMiddleware\" title=\"django.middleware.http.ConditionalGetMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ConditionalGetMiddleware</span></code></a></p>\n<p>Sebelum middleware apapun yang mungkin merubah tanggapan (itu menyetel kepala <code class=\"docutils literal notranslate\"><span class=\"pre\">ETag</span></code>).</p>\n<p>Setelah <code class=\"docutils literal notranslate\"><span class=\"pre\">GZipMiddleware</span></code> jadi itu tidak akan menghitung sebuah kepala <code class=\"docutils literal notranslate\"><span class=\"pre\">ETag</span></code> pada isi ter-gzip.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#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></p>\n<p>Salah satu yang paling atas, setelah <code class=\"docutils literal notranslate\"><span class=\"pre\">SessionMiddleware</span></code> (menggunakan data sesi) dan <code class=\"docutils literal notranslate\"><span class=\"pre\">UpdateCacheMiddleware</span></code> (merubah kepala <code class=\"docutils literal notranslate\"><span class=\"pre\">Vary</span></code>).</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.middleware.common.CommonMiddleware\" title=\"django.middleware.common.CommonMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">CommonMiddleware</span></code></a></p>\n<p>Sebelum middleware apapun yang mungkin merubah tanggapan (itu menyetel kepala <code class=\"docutils literal notranslate\"><span class=\"pre\">Content-Length</span></code>). Sebuah middleware yang muncul sebelum <code class=\"docutils literal notranslate\"><span class=\"pre\">CommonMiddleware</span></code> dan merubah tanggapan harus menyetel kembali <code class=\"docutils literal notranslate\"><span class=\"pre\">Content-Length</span></code>.</p>\n<p>Tutup ke atas: Itu akan mengalihkan ketika <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-APPEND_SLASH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">APPEND_SLASH</span></code></a> atau <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-PREPEND_WWW\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">PREPEND_WWW</span></code></a> menjadi <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>.</p>\n<p>After <code class=\"docutils literal notranslate\"><span class=\"pre\">SessionMiddleware</span></code> if you're using <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-CSRF_USE_SESSIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CSRF_USE_SESSIONS</span></code></a>.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.middleware.csrf.CsrfViewMiddleware\" title=\"django.middleware.csrf.CsrfViewMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">CsrfViewMiddleware</span></code></a></p>\n<p>Sebelum tampilan middleware apapunyang menganggap bahwa serangan CSRF telah ditangani.</p>\n<p>Before <a class=\"reference internal\" href=\"#django.contrib.auth.middleware.RemoteUserMiddleware\" title=\"django.contrib.auth.middleware.RemoteUserMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">RemoteUserMiddleware</span></code></a>, or any\nother authentication middleware that may perform a login, and hence rotate\nthe CSRF token, before calling down the middleware chain.</p>\n<p>After <code class=\"docutils literal notranslate\"><span class=\"pre\">SessionMiddleware</span></code> if you're using <a class=\"reference internal\" href=\"/id/5.1/ref/settings/#std-setting-CSRF_USE_SESSIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CSRF_USE_SESSIONS</span></code></a>.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.contrib.auth.middleware.AuthenticationMiddleware\" title=\"django.contrib.auth.middleware.AuthenticationMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AuthenticationMiddleware</span></code></a></p>\n<p>Setelah <code class=\"docutils literal notranslate\"><span class=\"pre\">SessionMiddleware</span></code>: gunakan penyimpanan sesi.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.contrib.auth.middleware.LoginRequiredMiddleware\" title=\"django.contrib.auth.middleware.LoginRequiredMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">LoginRequiredMiddleware</span></code></a></p>\n<aside class=\"version-note version-added\" data-version=\"5.1\">\n<p class=\"version-note-title\">New in Django 5.1</p></aside>\n<p>After <code class=\"docutils literal notranslate\"><span class=\"pre\">AuthenticationMiddleware</span></code>: uses user object.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.contrib.messages.middleware.MessageMiddleware\" title=\"django.contrib.messages.middleware.MessageMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">MessageMiddleware</span></code></a></p>\n<p>Setelah <code class=\"docutils literal notranslate\"><span class=\"pre\">SessionMiddleware</span></code>: dapat menggunakan penyimpanan berdasar-sesi.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.middleware.cache.FetchFromCacheMiddleware\" title=\"django.middleware.cache.FetchFromCacheMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">FetchFromCacheMiddleware</span></code></a></p>\n<p>Setelah middleware apapun yang merubah kepala <code class=\"docutils literal notranslate\"><span class=\"pre\">vary</span></code>: kepala itu digunakan untuk mengambil nilai untuk kunci-campuran cache.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"/id/5.1/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></p>\n<p>Should be near the bottom as it's a last-resort type of middleware.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"/id/5.1/ref/contrib/redirects/#django.contrib.redirects.middleware.RedirectFallbackMiddleware\" title=\"django.contrib.redirects.middleware.RedirectFallbackMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">RedirectFallbackMiddleware</span></code></a></p>\n<p>Should be near the bottom as it's a last-resort type of middleware.</p>\n</li>\n</ol>\n</section>","rootId":"module-django.middleware","toc":[{"title":"Middleware tersedia","anchor":"available-middleware","children":[{"title":"Middleware tembolok","anchor":"module-django.middleware.cache","children":[]},{"title":"Middleware \"Umum\"","anchor":"module-django.middleware.common","children":[]},{"title":"Middleware GZip","anchor":"module-django.middleware.gzip","children":[]},{"title":"Middleware GET bersyarat","anchor":"module-django.middleware.http","children":[]},{"title":"Middleware lokal","anchor":"module-django.middleware.locale","children":[]},{"title":"Middleware pesan","anchor":"module-django.contrib.messages.middleware","children":[]},{"title":"Middleware keamanan","anchor":"module-django.middleware.security","children":[{"title":"HTTP Strict Transport Security","anchor":"http-strict-transport-security","children":[]},{"title":"Referrer Policy","anchor":"referrer-policy","children":[]},{"title":"Cross-Origin Opener Policy","anchor":"cross-origin-opener-policy","children":[]},{"title":"X-Content-Type-Options: nosniff","anchor":"x-content-type-options-nosniff","children":[]},{"title":"Pengalihan SSL","anchor":"ssl-redirect","children":[]}]},{"title":"Middleware sesi","anchor":"module-django.contrib.sessions.middleware","children":[]},{"title":"Situs middleware","anchor":"module-django.contrib.sites.middleware","children":[]},{"title":"Middleware otentifikasi","anchor":"module-django.contrib.auth.middleware","children":[]},{"title":"Middleware perlindungan CSRF","anchor":"csrf-protection-middleware","children":[]},{"title":"Middleware X-Frame-Options","anchor":"x-frame-options-middleware","children":[]}]},{"title":"Pengurutan middleware","anchor":"middleware-ordering","children":[]}],"breadcrumbs":[{"docname":"ref/index","title":"Acuan API","url":"/id/5.1/ref/"}],"prev":{"docname":"ref/logging","title":"Pencatatan","url":"/id/5.1/ref/logging/"},"next":{"docname":"ref/migration-operations","title":"Tindakan Perpindahan","url":"/id/5.1/ref/migration-operations/"},"formats":{"html":"/id/5.1/ref/middleware/","markdown":"/id/5.1/ref/middleware.md","json":"/id/5.1/ref/middleware.json"},"source":"https://github.com/django/django/blob/stable/5.1.x/docs/ref/middleware.txt","official":"https://docs.djangoproject.com/id/5.1/ref/middleware/","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","it","pt-br","ko","es","el","pl"]}