Bagaimana mengembangkan dengan ASGILink to this heading
As well as WSGI, Django also supports deploying on ASGI, the emerging Python standard for asynchronous web servers and applications.
Django's 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:
Obyek aplikasiLink to this heading
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 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.
Konfigurasi modul pengaturanLink to this heading
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 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 ASGILink to this heading
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)