2
0

daphne.txt 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. =============================
  2. How to use Django with Daphne
  3. =============================
  4. :pypi:`Daphne <daphne>` is a pure-Python ASGI server for UNIX, maintained by
  5. members of the Django project. It acts as the reference server for ASGI.
  6. Installing Daphne
  7. ===================
  8. You can install Daphne with ``pip``:
  9. .. code-block:: shell
  10. python -m pip install daphne
  11. Running Django in Daphne
  12. ========================
  13. When Daphne is installed, a ``daphne`` command is available which starts the
  14. Daphne server process. At its simplest, Daphne needs to be called with the
  15. location of a module containing an ASGI application object, followed by what
  16. the application is called (separated by a colon).
  17. For a typical Django project, invoking Daphne would look like:
  18. .. code-block:: shell
  19. daphne myproject.asgi:application
  20. This will start one process listening on ``127.0.0.1:8000``. It requires that
  21. your project be on the Python path; to ensure that run this command from the
  22. same directory as your ``manage.py`` file.
  23. .. _daphne-runserver:
  24. Integration with ``runserver``
  25. ==============================
  26. Daphne provides a :djadmin:`runserver` command to serve your site under ASGI
  27. during development.
  28. This can be enabled by adding ``daphne`` to the start of your
  29. :setting:`INSTALLED_APPS` and adding an ``ASGI_APPLICATION`` setting pointing
  30. to your ASGI application object::
  31. INSTALLED_APPS = [
  32. "daphne",
  33. ...,
  34. ]
  35. ASGI_APPLICATION = "myproject.asgi.application"