部署 Quart#

不建议直接运行 Quart(通过 run())在生产环境中。相反,建议使用 Hypercorn 或其他 ASGI 服务器运行 Quart。这是因为 run() 启用了有助于开发但会降低生产性能的功能。Hypercorn 与 Quart 一起安装,默认情况下将在开发模式下用于提供请求(例如,使用 run())。

要将 Quart 与 ASGI 服务器一起使用,只需将服务器指向 Quart 应用程序,例如,

example.py#
 from quart import Quart

 app = Quart(__name__)

 @app.route('/')
 async def hello():
     return 'Hello World'

您可以使用 Hypercorn 运行,

hypercorn example:app

请参阅 Hypercorn 文档

其他 ASGI 服务器#

服务器名称

HTTP/2

HTTP/3

服务器推送

Websocket 响应

Hypercorn

Daphne

Uvicorn

无服务器部署#

要在 AWS Lambda 和 API Gateway 设置中部署 Quart,您需要使用专门的 ASGI 函数适配器。Mangum 是推荐的解决方案,它可以像这样简单:

from mangum import Mangum
from quart import Quart

app = Quart(__name__)

@app.route("/")
async def index():
    return "Hello, world!"

handler = Mangum(app)  # optionally set debug=True