“Django/docs/3.0.x/howto/deployment/asgi/uvicorn”的版本间差异

来自菜鸟教程
Django/docs/3.0.x/howto/deployment/asgi/uvicorn
跳转至:导航、​搜索
(autoload)
 
(Page commit)
 
第1行: 第1行:
 +
{{DISPLAYTITLE:如何在 Uvicorn 中使用 Django — Django 文档}}
 
<div id="how-to-use-django-with-uvicorn" class="section">
 
<div id="how-to-use-django-with-uvicorn" class="section">
  
= How to use Django with Uvicorn =
+
= 如何在 Uvicorn 中使用 Django =
  
[https://www.uvicorn.org/ Uvicorn] is an ASGI server based on <code>uvloop</code> and <code>httptools</code>, with an
+
[https://www.uvicorn.org/ Uvicorn]是一个基于<code>uvloop</code><code>httptools</code>的ASGI服务器,强调速度。
emphasis on speed.
 
  
 
<div id="installing-uvicorn" class="section">
 
<div id="installing-uvicorn" class="section">
  
== Installing Uvicorn ==
+
== 安装 Uvicorn ==
  
You can install Uvicorn with <code>pip</code>:
+
您可以使用 <code>pip</code> 安装 Uvicorn:
  
 
<div class="highlight-bash notranslate">
 
<div class="highlight-bash notranslate">
第16行: 第16行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>python -m pip install uvicorn</pre>
+
<syntaxhighlight lang="bash">python -m pip install uvicorn</syntaxhighlight>
  
 
</div>
 
</div>
第25行: 第25行:
 
<div id="running-django-in-uvicorn" class="section">
 
<div id="running-django-in-uvicorn" class="section">
  
== Running Django in Uvicorn ==
+
== 在 Uvicorn 中运行 Django ==
  
When Uvicorn is installed, a <code>uvicorn</code> command is available which runs ASGI
+
安装 Uvicorn 后,可以使用 <code>uvicorn</code> 命令来运行 ASGI 应用程序。 Uvicorn 需要使用包含 ASGI 应用程序对象的模块的位置来调用,然后是应用程序的名称(用冒号分隔)。
applications. Uvicorn needs to be called with the location of a module
 
containing a ASGI application object, followed by what the application is
 
called (separated by a colon).
 
  
For a typical Django project, invoking Uvicorn would look like:
+
对于典型的 Django 项目,调用 Uvicorn 将如下所示:
  
 
<div class="highlight-bash notranslate">
 
<div class="highlight-bash notranslate">
第38行: 第35行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>uvicorn myproject.asgi:application</pre>
+
<syntaxhighlight lang="bash">uvicorn myproject.asgi:application</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
它将开启一个进程,监听 <code>127.0.0.1:8000</code>。这需要你的项目位于 Python path 上。为了确保这点,你应该在与 <code>manage.py</code> 文件相同的路径中运行这个命令。
+
这将启动一个侦听 <code>127.0.0.1:8000</code> 的进程。 它要求你的项目在 Python 路径上; 确保从与 <code>manage.py</code> 文件相同的目录中运行此命令。
  
For more advanced usage, please read the [https://www.uvicorn.org/ Uvicorn documentation].
+
更多高级用法,请阅读 [https://www.uvicorn.org/ Uvicorn 文档]
  
  
第51行: 第48行:
  
 
</div>
 
</div>
 +
<div class="clearer">
  
[[Category:Django 3.0.x 中文文档]]
+
 
 +
 
 +
</div>
 +
 
 +
[[Category:Django 3.0.x 文档]]

2021年10月31日 (日) 04:08的最新版本

如何在 Uvicorn 中使用 Django

Uvicorn是一个基于uvloophttptools的ASGI服务器,强调速度。

安装 Uvicorn

您可以使用 pip 安装 Uvicorn:

python -m pip install uvicorn

在 Uvicorn 中运行 Django

安装 Uvicorn 后,可以使用 uvicorn 命令来运行 ASGI 应用程序。 Uvicorn 需要使用包含 ASGI 应用程序对象的模块的位置来调用,然后是应用程序的名称(用冒号分隔)。

对于典型的 Django 项目,调用 Uvicorn 将如下所示:

uvicorn myproject.asgi:application

这将启动一个侦听 127.0.0.1:8000 的进程。 它要求你的项目在 Python 路径上; 确保从与 manage.py 文件相同的目录中运行此命令。

更多高级用法,请阅读 Uvicorn 文档