From 016c3f0d5b0e11ee9d97ebc63249de1ee4e71a48 Mon Sep 17 00:00:00 2001 From: jaystone776 <1732865113@qq.com> Date: Fri, 30 Jul 2021 04:15:54 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=90=20Add=20Chinese=20translation=20fo?= =?UTF-8?q?r=20`docs/tutorial/dependencies/global-dependencies.md`=20(#349?= =?UTF-8?q?3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit as title --- .../dependencies/global-dependencies.md | 18 ++++++++++++++++++ docs/zh/mkdocs.yml | 2 ++ 2 files changed, 20 insertions(+) create mode 100644 docs/zh/docs/tutorial/dependencies/global-dependencies.md diff --git a/docs/zh/docs/tutorial/dependencies/global-dependencies.md b/docs/zh/docs/tutorial/dependencies/global-dependencies.md new file mode 100644 index 000000000..5c367ff09 --- /dev/null +++ b/docs/zh/docs/tutorial/dependencies/global-dependencies.md @@ -0,0 +1,18 @@ +# 全局依赖项 + +有时,我们要为整个应用添加依赖项。 + +通过与定义[*路径装饰器依赖项*](dependencies-in-path-operation-decorators.md){.internal-link target=_blank} 类似的方式,可以把依赖项添加至整个 `FastAPI` 应用。 + +这样一来,就可以为所有*路径操作*应用该依赖项: + +```Python hl_lines="15" +{!../../../docs_src/dependencies/tutorial012.py!} +``` + +[*路径装饰器依赖项*](dependencies-in-path-operation-decorators.md){.internal-link target=_blank} 一章的思路均适用于全局依赖项, 在本例中,这些依赖项可以用于应用中的所有*路径操作*。 + +## 为一组路径操作定义依赖项 + +稍后,[大型应用 - 多文件](../../tutorial/bigger-applications.md){.internal-link target=_blank}一章中会介绍如何使用多个文件创建大型应用程序,在这一章中,您将了解到如何为一组*路径操作*声明单个 `dependencies` 参数。 + diff --git a/docs/zh/mkdocs.yml b/docs/zh/mkdocs.yml index b7312b917..6fb6b191a 100644 --- a/docs/zh/mkdocs.yml +++ b/docs/zh/mkdocs.yml @@ -80,6 +80,8 @@ nav: - tutorial/request-forms-and-files.md - tutorial/handling-errors.md - tutorial/body-updates.md + - 依赖项: + - tutorial/dependencies/global-dependencies.md - 安全性: - tutorial/security/index.md - tutorial/security/get-current-user.md