{"title":"Django を Uvicorn とともに使う","version":"4.2","locale":"ja","docname":"howto/deployment/asgi/uvicorn","url":"/ja/4.2/howto/deployment/asgi/uvicorn/","canonical":"https://djangodocs.dev/ja/4.2/howto/deployment/asgi/uvicorn/","summary":"Uvicorn は uvloop と httptools をベースにした速度重視のASGIサーバーです。 Uvicorn のインストール Link to this heading # pip で Uvicorn をインストールします: Shell Copy python -m pip install uvicorn…","html":"<h1>Django を Uvicorn とともに使う<a class=\"heading-anchor\" href=\"#how-to-use-django-with-uvicorn\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p><a class=\"reference external\" href=\"https://www.uvicorn.org/\">Uvicorn</a> は <code class=\"docutils literal notranslate\"><span class=\"pre\">uvloop</span></code> と <code class=\"docutils literal notranslate\"><span class=\"pre\">httptools</span></code> をベースにした速度重視のASGIサーバーです。</p>\n<section id=\"installing-uvicorn\">\n<h2>Uvicorn のインストール<a class=\"heading-anchor\" href=\"#installing-uvicorn\"><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> で Uvicorn をインストールします:</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>uvicorn\n</code></pre></div>\n</section>\n<section id=\"running-django-in-uvicorn\">\n<h2>Uvicorn で Django を実行<a class=\"heading-anchor\" href=\"#running-django-in-uvicorn\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>When Uvicorn is installed, a <code class=\"docutils literal notranslate\"><span class=\"pre\">uvicorn</span></code> command is available which runs ASGI\napplications. Uvicorn needs to be called with the location of a module\ncontaining an ASGI application object, followed by what the application is\ncalled (separated by a colon).</p>\n<p>For a typical Django project, invoking Uvicorn would look like:</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>uvicorn<span class=\"w\"> </span>myproject.asgi:application\n</code></pre></div>\n<p>This will start one process listening on <code class=\"docutils literal notranslate\"><span class=\"pre\">127.0.0.1:8000</span></code>. It requires that\nyour project be on the Python path; to ensure that run this command from the\nsame directory as your <code class=\"docutils literal notranslate\"><span class=\"pre\">manage.py</span></code> file.</p>\n<p>In development mode, you can add <code class=\"docutils literal notranslate\"><span class=\"pre\">--reload</span></code> to cause the server to reload any\ntime a file is changed on disk.</p>\n<p>For more advanced usage, please read the <a class=\"reference external\" href=\"https://www.uvicorn.org/\">Uvicorn documentation</a>.</p>\n</section>\n<section id=\"deploying-django-using-uvicorn-and-gunicorn\">\n<h2>Deploying Django using Uvicorn and Gunicorn<a class=\"heading-anchor\" href=\"#deploying-django-using-uvicorn-and-gunicorn\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p><a class=\"reference external\" href=\"https://gunicorn.org/\">Gunicorn</a> は、プロセス監視と自動再起動を実装した堅牢なウェブサーバーです。本番環境でUvicornを運用する際に役立ちます。</p>\n<p>To install Uvicorn and Gunicorn, use the following:</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>uvicorn<span class=\"w\"> </span>gunicorn\n</code></pre></div>\n<p>Then start Gunicorn using the Uvicorn worker class like this:</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>gunicorn<span class=\"w\"> </span>myproject.asgi:application<span class=\"w\"> </span>-k<span class=\"w\"> </span>uvicorn.workers.UvicornWorker\n</code></pre></div>\n</section>","rootId":"how-to-use-django-with-uvicorn","toc":[{"title":"Uvicorn のインストール","anchor":"installing-uvicorn","children":[]},{"title":"Uvicorn で Django を実行","anchor":"running-django-in-uvicorn","children":[]},{"title":"Deploying Django using Uvicorn and Gunicorn","anchor":"deploying-django-using-uvicorn-and-gunicorn","children":[]}],"breadcrumbs":[{"docname":"howto/index","title":"「How-to」ガイド","url":"/ja/4.2/howto/"},{"docname":"howto/deployment/index","title":"Djangoをデプロイするには","url":"/ja/4.2/howto/deployment/"},{"docname":"howto/deployment/asgi/index","title":"ASGIでデプロイする","url":"/ja/4.2/howto/deployment/asgi/"}],"prev":{"docname":"howto/deployment/asgi/hypercorn","title":"Django を Hypercorn とともに使う","url":"/ja/4.2/howto/deployment/asgi/hypercorn/"},"next":{"docname":"howto/deployment/checklist","title":"デプロイチェックリスト","url":"/ja/4.2/howto/deployment/checklist/"},"formats":{"html":"/ja/4.2/howto/deployment/asgi/uvicorn/","markdown":"/ja/4.2/howto/deployment/asgi/uvicorn.md","json":"/ja/4.2/howto/deployment/asgi/uvicorn.json"},"source":"https://github.com/django/django/blob/stable/4.2.x/docs/howto/deployment/asgi/uvicorn.txt","official":"https://docs.djangoproject.com/ja/4.2/howto/deployment/asgi/uvicorn/","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"]}