{"title":"Bagaimana menyebarkan berkas tetap","version":"4.2","locale":"id","docname":"howto/static-files/deployment","url":"/id/4.2/howto/static-files/deployment/","canonical":"https://djangodocs.dev/id/4.2/howto/static-files/deployment/","summary":"Lihat juga Untuk perkenalan ke penggunaan django.contrib.staticfiles , lihat Bagaimana mengelola berkas statik (misalnya gambar, JavaScript, CSS) . Melayani berkas…","html":"<h1>Bagaimana menyebarkan berkas tetap<a class=\"heading-anchor\" href=\"#how-to-deploy-static-files\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<aside class=\"admonition admonition-seealso\">\n<p class=\"admonition-title\">Lihat juga</p>\n<p>Untuk perkenalan ke penggunaan <a class=\"reference internal\" href=\"/id/4.2/ref/contrib/staticfiles/#module-django.contrib.staticfiles\" title=\"django.contrib.staticfiles: An app for handling static files.\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.contrib.staticfiles</span></code></a>, lihat <a class=\"reference internal\" href=\"/id/4.2/howto/static-files/\"><span class=\"doc\">Bagaimana mengelola berkas statik (misalnya gambar, JavaScript, CSS)</span></a>.</p>\n</aside>\n<section id=\"serving-static-files-in-production\">\n<span id=\"staticfiles-production\"></span><h2>Melayani berkas statis di produksi<a class=\"heading-anchor\" href=\"#serving-static-files-in-production\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The basic outline of putting static files into production consists of two\nsteps: run the <a class=\"reference internal\" href=\"/id/4.2/ref/contrib/staticfiles/#django-admin-collectstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">collectstatic</span></code></a> command when static files change, then\narrange for the collected static files directory (<a class=\"reference internal\" href=\"/id/4.2/ref/settings/#std-setting-STATIC_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATIC_ROOT</span></code></a>) to be\nmoved to the static file server and served. Depending the <code class=\"docutils literal notranslate\"><span class=\"pre\">staticfiles</span></code>\n<a class=\"reference internal\" href=\"/id/4.2/ref/settings/#std-setting-STORAGES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STORAGES</span></code></a> alias, files may need to be moved to a new location\nmanually or the <a class=\"reference internal\" href=\"/id/4.2/ref/contrib/staticfiles/#django.contrib.staticfiles.storage.StaticFilesStorage.post_process\" title=\"django.contrib.staticfiles.storage.StaticFilesStorage.post_process\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">post_process</span></code></a> method of\nthe <code class=\"docutils literal notranslate\"><span class=\"pre\">Storage</span></code> class might take care of that.</p>\n<p>As with all deployment tasks, the devil's in the details. Every production\nsetup will be a bit different, so you'll need to adapt the basic outline to fit\nyour needs. Below are a few common patterns that might help.</p>\n<section id=\"serving-the-site-and-your-static-files-from-the-same-server\">\n<h3>Melayani situs dan berkas-berkas tetap anda dari peladen sama<a class=\"heading-anchor\" href=\"#serving-the-site-and-your-static-files-from-the-same-server\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Jika anda ingin melayani berkas-berkas tetap anda dari peladen sama yang sudah melayani situs anda, pengolahan mungkin terlihat sesuatu seperti:</p>\n<ul class=\"simple\">\n<li><p>Dorong kode anda ke atas ke peladen penyebaran.</p></li>\n<li><p>Di peladen, jalankan <a class=\"reference internal\" href=\"/id/4.2/ref/contrib/staticfiles/#django-admin-collectstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">collectstatic</span></code></a> untuk menyalin semua berkas statis kedalam <a class=\"reference internal\" href=\"/id/4.2/ref/settings/#std-setting-STATIC_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATIC_ROOT</span></code></a>.</p></li>\n<li><p>Konfigurasikan peladen jaringan anda untuk melayani berkas-berkas dalam <a class=\"reference internal\" href=\"/id/4.2/ref/settings/#std-setting-STATIC_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATIC_ROOT</span></code></a> dibawah URL <a class=\"reference internal\" href=\"/id/4.2/ref/settings/#std-setting-STATIC_URL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATIC_URL</span></code></a>. Sebagai contoh, ini <a class=\"reference internal\" href=\"/id/4.2/howto/deployment/wsgi/modwsgi/#serving-files\"><span class=\"std std-ref\">how to do this with Apache and mod_wsgi</span></a>.</p></li>\n</ul>\n<p>Anda mungkin akan ingin mengotomatisasi pengolahan ini, khususnya jika anda mendapatkan banyak peladen jaringan.</p>\n</section>\n<section id=\"serving-static-files-from-a-dedicated-server\">\n<h3>Melayani berkas statis dari sebuah server tersendiri<a class=\"heading-anchor\" href=\"#serving-static-files-from-a-dedicated-server\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Most larger Django sites use a separate web server -- i.e., one that's not also\nrunning Django -- for serving static files. This server often runs a different\ntype of web server -- faster but less full-featured. Some common choices are:</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference external\" href=\"https://nginx.org/en/\">Nginx</a></p></li>\n<li><p>Versi ringkas dari <a class=\"reference external\" href=\"https://httpd.apache.org/\">Apache</a></p></li>\n</ul>\n<p>Konfigurasi peladen ini diluar cakupan dari dokumen ini; periksa setiap dokumentasi masing-masing peladen untuk perintah.</p>\n<p>Sejak peladen berkas tetap anda tidak akan menjalankan Django, anda akan butuh merubah strategi penyebaran menjadi kelihatan sesuatu seperti:</p>\n<ul class=\"simple\">\n<li><p>Ketika berkas statis anda berubah, jalankan <a class=\"reference internal\" href=\"/id/4.2/ref/contrib/staticfiles/#django-admin-collectstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">collectstatic</span></code></a> secara lokal.</p></li>\n<li><p>Dorong <a class=\"reference internal\" href=\"/id/4.2/ref/settings/#std-setting-STATIC_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATIC_ROOT</span></code></a> lokal anda sampai pada peladen berkas tetap kedalam direktori yang sedang dilayani. <a class=\"reference external\" href=\"https://rsync.samba.org/\">rsync</a> adalah sebuah pilihan umum untuk langkah ini sejak dia hanya butuh memindahkan bit ke berkas-berkas tetap yang telah berubah.</p></li>\n</ul>\n</section>\n<section id=\"serving-static-files-from-a-cloud-service-or-cdn\">\n<span id=\"staticfiles-from-cdn\"></span><h3>Melayani berkas statis dari layanan cloud atau CDN<a class=\"heading-anchor\" href=\"#serving-static-files-from-a-cloud-service-or-cdn\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Another common tactic is to serve static files from a cloud storage provider\nlike Amazon's S3 and/or a CDN (content delivery network). This lets you\nignore the problems of serving static files and can often make for\nfaster-loading web pages (especially when using a CDN).</p>\n<p>Ketika menggunakan layanan ini, alurkerja dasar akan kelihatan sedikit seperti diatas, kecuali bahwa daripada menggunakan <code class=\"docutils literal notranslate\"><span class=\"pre\">rsync</span></code> untuk memindahkan berkas-berkas tetap anda ke peladen anda akan butuh untuk memindahkan berkas-berkas tetap ke penyedia panyimpanan atau CDN.</p>\n<p>There's any number of ways you might do this, but if the provider has an API,\nyou can use a <a class=\"reference internal\" href=\"/id/4.2/howto/custom-file-storage/\"><span class=\"doc\">custom file storage backend</span></a>\nto integrate the CDN with your Django project. If you've written or are using a\n3rd party custom storage backend, you can tell <a class=\"reference internal\" href=\"/id/4.2/ref/contrib/staticfiles/#django-admin-collectstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">collectstatic</span></code></a> to use\nit by setting <code class=\"docutils literal notranslate\"><span class=\"pre\">staticfiles</span></code> in <a class=\"reference internal\" href=\"/id/4.2/ref/settings/#std-setting-STORAGES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STORAGES</span></code></a>.</p>\n<p>Sebagai contoh, jika anda telah menulis sebuah backend penyimpanan S3 dalam <code class=\"docutils literal notranslate\"><span class=\"pre\">myproject.storage.S3Storage</span></code> anda dapat menggunakannya dengan:</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\">STORAGES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"c1\"># ...</span>\n    <span class=\"s2\">&quot;staticfiles&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span><span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;myproject.storage.S3Storage&quot;</span><span class=\"p\">}</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>Once that's done, all you have to do is run <a class=\"reference internal\" href=\"/id/4.2/ref/contrib/staticfiles/#django-admin-collectstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">collectstatic</span></code></a> and your\nstatic files would be pushed through your storage package up to S3. If you\nlater needed to switch to a different storage provider, you may only have to\nchange <code class=\"docutils literal notranslate\"><span class=\"pre\">staticfiles</span></code> in the <a class=\"reference internal\" href=\"/id/4.2/ref/settings/#std-setting-STORAGES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STORAGES</span></code></a> setting.</p>\n<p>Untuk rincian pada bagaimana anda menulis satu dari backend ini, lihat <a class=\"reference internal\" href=\"/id/4.2/howto/custom-file-storage/\"><span class=\"doc\">Bagaimana menulis kelas penyimpanan disesuaikan</span></a>. Ada aplikasi pihak 3 tersedia yang menyediakan backend penyimpanan untuk banyak API penyimpanan berkas umum. Titik awal bagus adalah <a class=\"reference external\" href=\"https://djangopackages.org/grids/g/storage-backends/\">overview at djangopackages.org</a>.</p>\n<aside class=\"version-note version-changed\" data-version=\"4.2\">\n<p class=\"version-note-title\">Changed in Django 4.2</p><p>The <a class=\"reference internal\" href=\"/id/4.2/ref/settings/#std-setting-STORAGES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STORAGES</span></code></a> setting was added.</p>\n</aside>\n</section>\n</section>\n<section id=\"learn-more\">\n<h2>Pelajari lagi<a class=\"heading-anchor\" href=\"#learn-more\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Untuk rincian lengkap pada semua pengaturan, perintah, cetakan etiket, dan potongan-potongan lainnya dalam <a class=\"reference internal\" href=\"/id/4.2/ref/contrib/staticfiles/#module-django.contrib.staticfiles\" title=\"django.contrib.staticfiles: An app for handling static files.\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.contrib.staticfiles</span></code></a>, lihat <a class=\"reference internal\" href=\"/id/4.2/ref/contrib/staticfiles/\"><span class=\"doc\">the staticfiles reference</span></a>.</p>\n</section>","rootId":"how-to-deploy-static-files","toc":[{"title":"Melayani berkas statis di produksi","anchor":"serving-static-files-in-production","children":[{"title":"Melayani situs dan berkas-berkas tetap anda dari peladen sama","anchor":"serving-the-site-and-your-static-files-from-the-same-server","children":[]},{"title":"Melayani berkas statis dari sebuah server tersendiri","anchor":"serving-static-files-from-a-dedicated-server","children":[]},{"title":"Melayani berkas statis dari layanan cloud atau CDN","anchor":"serving-static-files-from-a-cloud-service-or-cdn","children":[]}]},{"title":"Pelajari lagi","anchor":"learn-more","children":[]}],"breadcrumbs":[{"docname":"howto/index","title":"Panduan \"Bagaimana\"","url":"/id/4.2/howto/"}],"prev":{"docname":"howto/static-files/index","title":"Bagaimana mengelola berkas statik (misalnya gambar, JavaScript, CSS)","url":"/id/4.2/howto/static-files/"},"next":{"docname":"howto/windows","title":"Bagaimana memasang Django pada WIndows","url":"/id/4.2/howto/windows/"},"formats":{"html":"/id/4.2/howto/static-files/deployment/","markdown":"/id/4.2/howto/static-files/deployment.md","json":"/id/4.2/howto/static-files/deployment.json"},"source":"https://github.com/django/django/blob/stable/4.2.x/docs/howto/static-files/deployment.txt","official":"https://docs.djangoproject.com/id/4.2/howto/static-files/deployment/","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"]}