{"title":"Bagaimana mengembangkan dengan ASGI","version":"3.2","locale":"id","docname":"howto/deployment/asgi/index","url":"/id/3.2/howto/deployment/asgi/","canonical":"https://djangodocs.dev/id/3.2/howto/deployment/asgi/","summary":"As well as WSGI, Django also supports deploying on ASGI , the emerging Python standard for asynchronous web servers and applications. Django's startproject…","html":"<h1>Bagaimana mengembangkan dengan ASGI<a class=\"heading-anchor\" href=\"#how-to-deploy-with-asgi\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>As well as WSGI, Django also supports deploying on <a class=\"reference external\" href=\"https://asgi.readthedocs.io/en/latest/\">ASGI</a>, the emerging Python\nstandard for asynchronous web servers and applications.</p>\n<p>Django's <a class=\"reference internal\" href=\"/id/3.2/ref/django-admin/#django-admin-startproject\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">startproject</span></code></a> management command sets up a default ASGI\nconfiguration for you, which you can tweak as needed for your project, and\ndirect any ASGI-compliant application server to use.</p>\n<p>Django menyertakan dokumentasi mulai untuk peladen ASGI berikut:</p>\n<div class=\"toctree-wrapper compound\">\n<ul>\n<li class=\"toctree-l1\"><a class=\"reference internal\" href=\"/id/3.2/howto/deployment/asgi/daphne/\">Bagaimana menggunakan Django dengan Daphne</a></li>\n<li class=\"toctree-l1\"><a class=\"reference internal\" href=\"/id/3.2/howto/deployment/asgi/hypercorn/\">Bagaimana menggunakan Django dengan Hypercorn</a></li>\n<li class=\"toctree-l1\"><a class=\"reference internal\" href=\"/id/3.2/howto/deployment/asgi/uvicorn/\">Bagaimana menggunakan Django dengan Uvicorn</a></li>\n</ul>\n</div>\n<section id=\"the-application-object\">\n<h2>Obyek <code class=\"docutils literal notranslate\"><span class=\"pre\">aplikasi</span></code><a class=\"heading-anchor\" href=\"#the-application-object\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Like WSGI, ASGI has you supply an <code class=\"docutils literal notranslate\"><span class=\"pre\">application</span></code> callable which\nthe application server uses to communicate with your code. It's commonly\nprovided as an object named <code class=\"docutils literal notranslate\"><span class=\"pre\">application</span></code> in a Python module accessible to\nthe server.</p>\n<p>Perintah <a class=\"reference internal\" href=\"/id/3.2/ref/django-admin/#django-admin-startproject\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">startproject</span></code></a> membuat sebuah berkas <code class=\"file docutils literal notranslate\"><span class=\"pre\">&lt;project_name&gt;/asgi.py</span></code> yang mengandung seperti <code class=\"docutils literal notranslate\"><span class=\"pre\">application</span></code> dapat dipanggil.</p>\n<p>It's not used by the development server (<code class=\"docutils literal notranslate\"><span class=\"pre\">runserver</span></code>), but can be used by\nany ASGI server either in development or in production.</p>\n<p>ASGI servers usually take the path to the application callable as a string;\nfor most Django projects, this will look like <code class=\"docutils literal notranslate\"><span class=\"pre\">myproject.asgi:application</span></code>.</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Peringatan</p>\n<p>Selagi penangan ASGI awalan Django akan menjalankan semua kode anda dalam antrian sinkronus, jika anda memilih menjalankan penangan asinkronus anda waspada terhadap keamanan-asinkronus.</p>\n<p>Do not call blocking synchronous functions or libraries in any async code.\nDjango prevents you from doing this with the parts of Django that are not\nasync-safe, but the same may not be true of third-party apps or Python\nlibraries.</p>\n</aside>\n</section>\n<section id=\"configuring-the-settings-module\">\n<h2>Konfigurasi modul pengaturan<a class=\"heading-anchor\" href=\"#configuring-the-settings-module\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>When the ASGI server loads your application, Django needs to import the\nsettings module — that's where your entire application is defined.</p>\n<p>Django menggunakan lingkungan variabel  <span class=\"target\" id=\"index-2\"></span><a class=\"reference internal\" href=\"/id/3.2/topics/settings/#envvar-DJANGO_SETTINGS_MODULE\"><code class=\"xref std std-envvar docutils literal notranslate\"><span class=\"pre\">DJANGO_SETTINGS_MODULE</span></code></a> untuk menempatkan modul pengaturan yang sesuai. Dia harus mengandung jalur titik pada modul pengaturan. Anda dapat menggunakan nilai berbeda untuk pengembangan dan produksi; dia semua tergantung pada bagaimana anda mengorganisasikan pengaturan anda.</p>\n<p>Jika variabel ini tidak disetel, awalan <code class=\"file docutils literal notranslate\"><span class=\"pre\">asgi.py</span></code> mensetel itu menjadi <code class=\"docutils literal notranslate\"><span class=\"pre\">mysite.settings</span></code>, dimana <code class=\"docutils literal notranslate\"><span class=\"pre\">mysite</span></code> adalah nama dari proyek anda.</p>\n</section>\n<section id=\"applying-asgi-middleware\">\n<h2>Memberlakukan middleware ASGI<a class=\"heading-anchor\" href=\"#applying-asgi-middleware\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Untuk memberlakukan middleware ASGI, atau membungkus Django dalam aplikasi ASGI lain, anda dapat membungkus objek <code class=\"docutils literal notranslate\"><span class=\"pre\">application</span></code> Django di berkas <code class=\"docutils literal notranslate\"><span class=\"pre\">asgi.py</span></code>. 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\">from</span><span class=\"w\"> </span><span class=\"nn\">some_asgi_library</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">AmazingMiddleware</span>\n<span class=\"n\">application</span> <span class=\"o\">=</span> <span class=\"n\">AmazingMiddleware</span><span class=\"p\">(</span><span class=\"n\">application</span><span class=\"p\">)</span>\n</code></pre></div>\n</section>","rootId":"how-to-deploy-with-asgi","toc":[{"title":"Obyek aplikasi","anchor":"the-application-object","children":[]},{"title":"Konfigurasi modul pengaturan","anchor":"configuring-the-settings-module","children":[]},{"title":"Memberlakukan middleware ASGI","anchor":"applying-asgi-middleware","children":[]}],"breadcrumbs":[{"docname":"howto/index","title":"Panduan \"Bagaimana\"","url":"/id/3.2/howto/"},{"docname":"howto/deployment/index","title":"Menyebarkan Django","url":"/id/3.2/howto/deployment/"}],"prev":{"docname":"howto/deployment/wsgi/apache-auth","title":"Otentifikasi terhadap pengguna basisdata Django dari Apache","url":"/id/3.2/howto/deployment/wsgi/apache-auth/"},"next":{"docname":"howto/deployment/asgi/daphne","title":"Bagaimana menggunakan Django dengan Daphne","url":"/id/3.2/howto/deployment/asgi/daphne/"},"formats":{"html":"/id/3.2/howto/deployment/asgi/","markdown":"/id/3.2/howto/deployment/asgi.md","json":"/id/3.2/howto/deployment/asgi.json"},"source":"https://github.com/django/django/blob/stable/3.2.x/docs/howto/deployment/asgi/index.txt","official":"https://docs.djangoproject.com/id/3.2/howto/deployment/asgi/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0"],"inLocales":["en","zh-hans","fr","ja","id","it","pt-br","ko","es","el","pl"]}