{"title":"如何使用 Hypercorn 托管 Django。","version":"6.0","locale":"zh-hans","docname":"howto/deployment/asgi/hypercorn","url":"/zh-hans/6.0/howto/deployment/asgi/hypercorn/","canonical":"https://djangodocs.dev/zh-hans/6.0/howto/deployment/asgi/hypercorn/","summary":"Hypercorn 是一个加强支持HTTP/1，HTTP/2和HTTP/3的ASGI服务器。 安装Hypercorn Link to this heading # 你可以使用 pip 安装 Hypercorn： Shell Copy python -m pip install hypercorn…","html":"<h1>如何使用 Hypercorn 托管 Django。<a class=\"heading-anchor\" href=\"#how-to-use-django-with-hypercorn\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p><a class=\"reference external\" href=\"https://hypercorn.readthedocs.io/\">Hypercorn</a> 是一个加强支持HTTP/1，HTTP/2和HTTP/3的ASGI服务器。</p>\n<section id=\"installing-hypercorn\">\n<h2>安装Hypercorn<a class=\"heading-anchor\" href=\"#installing-hypercorn\"><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> 安装 Hypercorn：</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>hypercorn\n</code></pre></div>\n</section>\n<section id=\"running-django-in-hypercorn\">\n<h2>在Hypercorn中运行Django<a class=\"heading-anchor\" href=\"#running-django-in-hypercorn\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>安装 <a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/Hypercorn/\">Hypercorn</a> 后，会有一个 <code class=\"docutils literal notranslate\"><span class=\"pre\">hypercorn</span></code> 命令可用，它运行 ASGI 应用程序。Hypercorn 需要使用包含 ASGI 应用程序对象的模块的位置调用，后跟应用程序的名称（用冒号分隔）。</p>\n<p>对于一个典型的 Django 项目，调用 Hypercorn 的方式如下：</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>hypercorn<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>。这需要你的项目位于 Python path 上。为了确保这点，你应该在与 <code class=\"docutils literal notranslate\"><span class=\"pre\">manage.py</span></code> 文件相同的路径中运行这个命令。</p>\n<p>有关更多的高级用法，请参阅 <a class=\"reference external\" href=\"https://hypercorn.readthedocs.io/\">Hypercorn documentation 1</a>.</p>\n</section>","rootId":"how-to-use-django-with-hypercorn","toc":[{"title":"安装Hypercorn","anchor":"installing-hypercorn","children":[]},{"title":"在Hypercorn中运行Django","anchor":"running-django-in-hypercorn","children":[]}],"breadcrumbs":[{"docname":"howto/index","title":"如何引导","url":"/zh-hans/6.0/howto/"},{"docname":"howto/deployment/index","title":"如何部署 Django","url":"/zh-hans/6.0/howto/deployment/"},{"docname":"howto/deployment/asgi/index","title":"如何使用 ASGI 来部署","url":"/zh-hans/6.0/howto/deployment/asgi/"}],"prev":{"docname":"howto/deployment/asgi/daphne","title":"如何使用 Daphne 托管 Django","url":"/zh-hans/6.0/howto/deployment/asgi/daphne/"},"next":{"docname":"howto/deployment/asgi/uvicorn","title":"如何使用 Uvicorn 托管 Django","url":"/zh-hans/6.0/howto/deployment/asgi/uvicorn/"},"formats":{"html":"/zh-hans/6.0/howto/deployment/asgi/hypercorn/","markdown":"/zh-hans/6.0/howto/deployment/asgi/hypercorn.md","json":"/zh-hans/6.0/howto/deployment/asgi/hypercorn.json"},"source":"https://github.com/django/django/blob/stable/6.0.x/docs/howto/deployment/asgi/hypercorn.txt","official":"https://docs.djangoproject.com/zh-hans/6.0/howto/deployment/asgi/hypercorn/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}