---
title: "Bagaimana mengembangkan dengan ASGI"
version: 3.2
locale: id
source: https://docs.djangoproject.com/id/3.2/howto/deployment/asgi/
canonical: https://djangodocs.dev/id/3.2/howto/deployment/asgi/
---
# Bagaimana mengembangkan dengan ASGI

As well as WSGI, Django also supports deploying on [ASGI](https://asgi.readthedocs.io/en/latest/), the emerging Python
standard for asynchronous web servers and applications.

Django's [`startproject`](/id/3.2/ref/django-admin/#django-admin-startproject) management command sets up a default ASGI
configuration for you, which you can tweak as needed for your project, and
direct any ASGI-compliant application server to use.

Django menyertakan dokumentasi mulai untuk peladen ASGI berikut:

- [Bagaimana menggunakan Django dengan Daphne](/id/3.2/howto/deployment/asgi/daphne/)
- [Bagaimana menggunakan Django dengan Hypercorn](/id/3.2/howto/deployment/asgi/hypercorn/)
- [Bagaimana menggunakan Django dengan Uvicorn](/id/3.2/howto/deployment/asgi/uvicorn/)

## Obyek `aplikasi`

Like WSGI, ASGI has you supply an `application` callable which
the application server uses to communicate with your code. It's commonly
provided as an object named `application` in a Python module accessible to
the server.

Perintah [`startproject`](/id/3.2/ref/django-admin/#django-admin-startproject) membuat sebuah berkas `<project_name>/asgi.py` yang mengandung seperti `application` dapat dipanggil.

It's not used by the development server (`runserver`), but can be used by
any ASGI server either in development or in production.

ASGI servers usually take the path to the application callable as a string;
for most Django projects, this will look like `myproject.asgi:application`.

> **Warning**
>
> Selagi penangan ASGI awalan Django akan menjalankan semua kode anda dalam antrian sinkronus, jika anda memilih menjalankan penangan asinkronus anda waspada terhadap keamanan-asinkronus.
>
> Do not call blocking synchronous functions or libraries in any async code.
> Django prevents you from doing this with the parts of Django that are not
> async-safe, but the same may not be true of third-party apps or Python
> libraries.

## Konfigurasi modul pengaturan

When the ASGI server loads your application, Django needs to import the
settings module — that's where your entire application is defined.

Django menggunakan lingkungan variabel  [`DJANGO_SETTINGS_MODULE`](/id/3.2/topics/settings/#envvar-DJANGO_SETTINGS_MODULE) 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.

Jika variabel ini tidak disetel, awalan `asgi.py` mensetel itu menjadi `mysite.settings`, dimana `mysite` adalah nama dari proyek anda.

## Memberlakukan middleware ASGI

Untuk memberlakukan middleware ASGI, atau membungkus Django dalam aplikasi ASGI lain, anda dapat membungkus objek `application` Django di berkas `asgi.py`. Sebagai contoh:

```
from some_asgi_library import AmazingMiddleware
application = AmazingMiddleware(application)
```
