From 1a8ccf87a4657ff962e738bd53414a2b5de7191c Mon Sep 17 00:00:00 2001 From: KellyAlsa-massive-win Date: Thu, 3 Feb 2022 16:31:20 +0800 Subject: [PATCH 1/3] add Chinese translation for docs/advanced/wsgi.md --- docs/zh/docs/advanced/wsgi.md | 37 +++++++++++++++++++++++++++++++++++ docs/zh/mkdocs.yml | 1 + 2 files changed, 38 insertions(+) create mode 100644 docs/zh/docs/advanced/wsgi.md diff --git a/docs/zh/docs/advanced/wsgi.md b/docs/zh/docs/advanced/wsgi.md new file mode 100644 index 0000000000000..865be84047ff5 --- /dev/null +++ b/docs/zh/docs/advanced/wsgi.md @@ -0,0 +1,37 @@ +# 包含WSGI应用 - Flask,Django,和其它 + +您可以挂载多个WSGI应用,正如您在 [Sub Applications - Mounts](./sub-applications.md){.internal-link target=_blank}, [Behind a Proxy](./behind-a-proxy.md){.internal-link target=_blank} 中所看到的那样。 + +为此, 您可以使用 `WSGIMiddleware` 来包装其它框架下的 WSGI 应用,比方说:Flask,Django,等。 + +## 使用 `WSGIMiddleware` + +您需要导入 `WSGIMiddleware`。 + +然后使用该中间件包装您的 WSGI 应用(例如 Flask)。 + +之后将其挂载到某一个路径下。 + +```Python hl_lines="2-3 22" +{!../../../docs_src/wsgi/tutorial001.py!} +``` + +## 检查 + +现在,所有定义在 `/v1/` 路径下的请求将会被 Flask 应用处理。 + +其余的请求则会被 **FastAPI** 处理。 + +如果您使用 Uvicorn 运行应用实例并且访问 http://localhost:8000/v1/,您将会看到由 Flask 返回的响应: + +```txt +Hello, World from Flask! +``` + +并且如果您访问 http://localhost:8000/v2,您将会看到由 FastAPI 返回的响应: + +```JSON +{ + "message": "Hello World" +} +``` diff --git a/docs/zh/mkdocs.yml b/docs/zh/mkdocs.yml index 1d050fddd75fb..b6903071f0e9d 100644 --- a/docs/zh/mkdocs.yml +++ b/docs/zh/mkdocs.yml @@ -100,6 +100,7 @@ nav: - advanced/additional-status-codes.md - advanced/response-directly.md - advanced/custom-response.md + - advanced/wsgi.md - contributing.md - help-fastapi.md - benchmarks.md From 0109449ee5959a23677d642216e76345e8ed8edb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 6 Sep 2022 07:00:48 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20for?= =?UTF-8?q?mat=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/docs/advanced/wsgi.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/zh/docs/advanced/wsgi.md b/docs/zh/docs/advanced/wsgi.md index 865be84047ff5..24477869e5da9 100644 --- a/docs/zh/docs/advanced/wsgi.md +++ b/docs/zh/docs/advanced/wsgi.md @@ -1,5 +1,5 @@ # 包含WSGI应用 - Flask,Django,和其它 - + 您可以挂载多个WSGI应用,正如您在 [Sub Applications - Mounts](./sub-applications.md){.internal-link target=_blank}, [Behind a Proxy](./behind-a-proxy.md){.internal-link target=_blank} 中所看到的那样。 为此, 您可以使用 `WSGIMiddleware` 来包装其它框架下的 WSGI 应用,比方说:Flask,Django,等。 From 333b205feb884efc64ee1655c3c05e3e8ed3e9e3 Mon Sep 17 00:00:00 2001 From: ASpathfinder <31813636+ASpathfinder@users.noreply.github.com> Date: Wed, 19 Oct 2022 09:51:30 +0800 Subject: [PATCH 3/3] Apply suggestions from code review Fix some translation errors Co-authored-by: Jeodre --- docs/zh/docs/advanced/wsgi.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/zh/docs/advanced/wsgi.md b/docs/zh/docs/advanced/wsgi.md index 24477869e5da9..ad71280fc6180 100644 --- a/docs/zh/docs/advanced/wsgi.md +++ b/docs/zh/docs/advanced/wsgi.md @@ -1,14 +1,14 @@ -# 包含WSGI应用 - Flask,Django,和其它 +# 包含 WSGI - Flask,Django,其它 -您可以挂载多个WSGI应用,正如您在 [Sub Applications - Mounts](./sub-applications.md){.internal-link target=_blank}, [Behind a Proxy](./behind-a-proxy.md){.internal-link target=_blank} 中所看到的那样。 +您可以挂载多个 WSGI 应用,正如您在 [Sub Applications - Mounts](./sub-applications.md){.internal-link target=_blank}, [Behind a Proxy](./behind-a-proxy.md){.internal-link target=_blank} 中所看到的那样。 -为此, 您可以使用 `WSGIMiddleware` 来包装其它框架下的 WSGI 应用,比方说:Flask,Django,等。 +为此, 您可以使用 `WSGIMiddleware` 来包装你的 WSGI 应用,如:Flask,Django,等等。 ## 使用 `WSGIMiddleware` 您需要导入 `WSGIMiddleware`。 -然后使用该中间件包装您的 WSGI 应用(例如 Flask)。 +然后使用该中间件包装 WSGI 应用(例如 Flask)。 之后将其挂载到某一个路径下。