{"title":"How to use Django with Granian","version":"6.1","locale":"zh-hans","docname":"howto/deployment/wsgi/granian","url":"/zh-hans/6.1/howto/deployment/wsgi/granian/","canonical":"https://djangodocs.dev/zh-hans/6.1/howto/deployment/wsgi/granian/","summary":"Granian is a Rust-based high-performance HTTP server for Python applications, supporting ASGI and WSGI interfaces. Installing Granian Link to this heading # You can…","html":"<h1>How to use Django with Granian<a class=\"heading-anchor\" href=\"#how-to-use-django-with-granian\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p><a class=\"reference external\" href=\"https://github.com/emmett-framework/granian\">Granian</a> is a Rust-based high-performance HTTP server for Python applications,\nsupporting ASGI and WSGI interfaces.</p>\n<section id=\"installing-granian\">\n<h2>Installing Granian<a class=\"heading-anchor\" href=\"#installing-granian\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>You can install Granian with <code class=\"docutils literal notranslate\"><span class=\"pre\">pip</span></code>:</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>granian\n</code></pre></div>\n</section>\n<section id=\"running-django-in-granian\">\n<h2>Running Django in Granian<a class=\"heading-anchor\" href=\"#running-django-in-granian\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>When Granian is installed, a <code class=\"docutils literal notranslate\"><span class=\"pre\">granian</span></code> command is available which runs WSGI\napplications. Granian needs to be called with the location of a module\ncontaining a WSGI application object named <code class=\"docutils literal notranslate\"><span class=\"pre\">application</span></code>, using the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">--interface</span> <span class=\"pre\">wsgi</span></code> option.</p>\n<p>For a typical Django project, invoking Granian 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>granian<span class=\"w\"> </span>myproject.wsgi:application<span class=\"w\"> </span>--interface<span class=\"w\"> </span>wsgi\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>For more advanced usage, please read the <a class=\"reference external\" href=\"https://github.com/emmett-framework/granian\">Granian documentation</a>.</p>\n</section>","rootId":"how-to-use-django-with-granian","toc":[{"title":"Installing Granian","anchor":"installing-granian","children":[]},{"title":"Running Django in Granian","anchor":"running-django-in-granian","children":[]}],"breadcrumbs":[{"docname":"howto/index","title":"如何引导","url":"/zh-hans/6.1/howto/"},{"docname":"howto/deployment/index","title":"如何部署 Django","url":"/zh-hans/6.1/howto/deployment/"},{"docname":"howto/deployment/wsgi/index","title":"如何使用 WSGI 进行部署","url":"/zh-hans/6.1/howto/deployment/wsgi/"}],"prev":{"docname":"howto/deployment/wsgi/index","title":"如何使用 WSGI 进行部署","url":"/zh-hans/6.1/howto/deployment/wsgi/"},"next":{"docname":"howto/deployment/wsgi/gunicorn","title":"如何使用 Gunicorn 托管 Django","url":"/zh-hans/6.1/howto/deployment/wsgi/gunicorn/"},"formats":{"html":"/zh-hans/6.1/howto/deployment/wsgi/granian/","markdown":"/zh-hans/6.1/howto/deployment/wsgi/granian.md","json":"/zh-hans/6.1/howto/deployment/wsgi/granian.json"},"source":"https://github.com/django/django/blob/stable/6.1.x/docs/howto/deployment/wsgi/granian.txt","official":"https://docs.djangoproject.com/zh-hans/6.1/howto/deployment/wsgi/granian/","inVersions":["6.1"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}