{"title":"Django を Daphne とともに使う","version":"6.0","locale":"ja","docname":"howto/deployment/asgi/daphne","url":"/ja/6.0/howto/deployment/asgi/daphne/","canonical":"https://djangodocs.dev/ja/6.0/howto/deployment/asgi/daphne/","summary":"Daphne は、pure-Pythonで書かれたUNIX向けのASGIサーバーで、Djangoプロジェクトのメンバーによってメンテナンスされています。これはASGIのリファレンス実装のサーバーとして機能します。 Daphneのインストール Link to this heading # pip で Daphne…","html":"<h1>Django を Daphne とともに使う<a class=\"heading-anchor\" href=\"#how-to-use-django-with-daphne\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p><a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/daphne/\">Daphne</a> は、pure-Pythonで書かれたUNIX向けのASGIサーバーで、Djangoプロジェクトのメンバーによってメンテナンスされています。これはASGIのリファレンス実装のサーバーとして機能します。</p>\n<section id=\"installing-daphne\">\n<h2>Daphneのインストール<a class=\"heading-anchor\" href=\"#installing-daphne\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">pip</span></code> で Daphne をインストールします:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</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=\"Shell code\"><code>python<span class=\"w\"> </span>-m<span class=\"w\"> </span>pip<span class=\"w\"> </span>install<span class=\"w\"> </span>daphne\n</code></pre></div>\n</section>\n<section id=\"running-django-in-daphne\">\n<h2>Daphne で Django を実行<a class=\"heading-anchor\" href=\"#running-django-in-daphne\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Daphne がインストールされると、Daphne サーバプロセスを起動する <code class=\"docutils literal notranslate\"><span class=\"pre\">daphne</span></code> コマンドが利用できるようになります。Daphne を呼び出すには、ASGI アプリケーションオブジェクトを含むモジュールの場所と、それに続いてアプリケーションの名前を（コロンで区切って）指定する必要があります。</p>\n<p>典型的な Django プロジェクトでは、Daphne の起動は次のようになります:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</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=\"Shell code\"><code>daphne<span class=\"w\"> </span>myproject.asgi:application\n</code></pre></div>\n<p>このコマンドは <code class=\"docutils literal notranslate\"><span class=\"pre\">127.0.0.1:8000</span></code> を待ち受けるプロセスを1つ起動します。プロジェクトは Python のパス上にある必要があります。それを確実にするために、 <code class=\"docutils literal notranslate\"><span class=\"pre\">manage.py</span></code> ファイルと同じディレクトリからこのコマンドを実行してください。</p>\n</section>\n<section id=\"integration-with-runserver\">\n<span id=\"daphne-runserver\"></span><h2><code class=\"docutils literal notranslate\"><span class=\"pre\">runserver</span></code> との統合<a class=\"heading-anchor\" href=\"#integration-with-runserver\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Daphneは開発中にASGIでサイトを動かすための <a class=\"reference internal\" href=\"/ja/6.0/ref/django-admin/#django-admin-runserver\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">runserver</span></code></a> コマンドを提供しています。</p>\n<p>これは <a class=\"reference internal\" href=\"/ja/6.0/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a> の先頭に <code class=\"docutils literal notranslate\"><span class=\"pre\">daphne</span></code> を追加し、ASGI アプリケーションオブジェクトを指す <code class=\"docutils literal notranslate\"><span class=\"pre\">ASGI_APPLICATION</span></code> 設定を追加することで有効になります:</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\">INSTALLED_APPS</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"s2\">&quot;daphne&quot;</span><span class=\"p\">,</span>\n    <span class=\"o\">...</span><span class=\"p\">,</span>\n<span class=\"p\">]</span>\n\n<span class=\"n\">ASGI_APPLICATION</span> <span class=\"o\">=</span> <span class=\"s2\">&quot;myproject.asgi.application&quot;</span>\n</code></pre></div>\n</section>","rootId":"how-to-use-django-with-daphne","toc":[{"title":"Daphneのインストール","anchor":"installing-daphne","children":[]},{"title":"Daphne で Django を実行","anchor":"running-django-in-daphne","children":[]},{"title":"runserver との統合","anchor":"integration-with-runserver","children":[]}],"breadcrumbs":[{"docname":"howto/index","title":"How-to ガイド","url":"/ja/6.0/howto/"},{"docname":"howto/deployment/index","title":"Djangoをデプロイするには","url":"/ja/6.0/howto/deployment/"},{"docname":"howto/deployment/asgi/index","title":"ASGI とともにデプロイするには","url":"/ja/6.0/howto/deployment/asgi/"}],"prev":{"docname":"howto/deployment/asgi/index","title":"ASGI とともにデプロイするには","url":"/ja/6.0/howto/deployment/asgi/"},"next":{"docname":"howto/deployment/asgi/hypercorn","title":"Django を Hypercorn とともに使う","url":"/ja/6.0/howto/deployment/asgi/hypercorn/"},"formats":{"html":"/ja/6.0/howto/deployment/asgi/daphne/","markdown":"/ja/6.0/howto/deployment/asgi/daphne.md","json":"/ja/6.0/howto/deployment/asgi/daphne.json"},"source":"https://github.com/django/django/blob/stable/6.0.x/docs/howto/deployment/asgi/daphne.txt","official":"https://docs.djangoproject.com/ja/6.0/howto/deployment/asgi/daphne/","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","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}