Skip to content

Commit

Permalink
📝 Add location info to tutorial/bigger-applications.md (#10552)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilslindemann committed Jan 11, 2024
1 parent cb95d1c commit 6bda132
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
26 changes: 13 additions & 13 deletions docs/em/docs/tutorial/bigger-applications.md
Expand Up @@ -79,7 +79,7 @@

👆 🗄 ⚫️ & ✍ "👐" 🎏 🌌 👆 🔜 ⏮️ 🎓 `FastAPI`:

```Python hl_lines="1 3"
```Python hl_lines="1 3" title="app/routers/users.py"
{!../../../docs_src/bigger_applications/app/routers/users.py!}
```

Expand All @@ -89,7 +89,7 @@

⚙️ ⚫️ 🎏 🌌 👆 🔜 ⚙️ `FastAPI` 🎓:

```Python hl_lines="6 11 16"
```Python hl_lines="6 11 16" title="app/routers/users.py"
{!../../../docs_src/bigger_applications/app/routers/users.py!}
```

Expand All @@ -112,7 +112,7 @@

👥 🔜 🔜 ⚙️ 🙅 🔗 ✍ 🛃 `X-Token` 🎚:

```Python hl_lines="1 4-6"
```Python hl_lines="1 4-6" title="app/dependencies.py"
{!../../../docs_src/bigger_applications/app/dependencies.py!}
```

Expand Down Expand Up @@ -143,7 +143,7 @@

, ↩️ ❎ 🌐 👈 🔠 *➡ 🛠️*, 👥 💪 🚮 ⚫️ `APIRouter`.

```Python hl_lines="5-10 16 21"
```Python hl_lines="5-10 16 21" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```

Expand Down Expand Up @@ -195,7 +195,7 @@ async def read_item(item_id: str):

👥 ⚙️ ⚖ 🗄 ⏮️ `..` 🔗:

```Python hl_lines="3"
```Python hl_lines="3" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```

Expand Down Expand Up @@ -265,7 +265,7 @@ that 🔜 ⛓:

✋️ 👥 💪 🚮 _🌅_ `tags` 👈 🔜 ✔ 🎯 *➡ 🛠️*, &`responses` 🎯 👈 *➡ 🛠️*:

```Python hl_lines="30-31"
```Python hl_lines="30-31" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```

Expand All @@ -290,15 +290,15 @@ that 🔜 ⛓:

& 👥 💪 📣 [🌐 🔗](dependencies/global-dependencies.md){.internal-link target=_blank} 👈 🔜 🌀 ⏮️ 🔗 🔠 `APIRouter`:

```Python hl_lines="1 3 7"
```Python hl_lines="1 3 7" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```

### 🗄 `APIRouter`

🔜 👥 🗄 🎏 🔁 👈 ✔️ `APIRouter`Ⓜ:

```Python hl_lines="5"
```Python hl_lines="5" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```

Expand Down Expand Up @@ -360,15 +360,15 @@ from .routers.users import router

, 💪 ⚙️ 👯‍♂️ 👫 🎏 📁, 👥 🗄 🔁 🔗:

```Python hl_lines="4"
```Python hl_lines="5" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```

### 🔌 `APIRouter``users` & `items`

🔜, ➡️ 🔌 `router`Ⓜ ⚪️➡️ 🔁 `users` & `items`:

```Python hl_lines="10-11"
```Python hl_lines="10-11" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```

Expand Down Expand Up @@ -401,15 +401,15 @@ from .routers.users import router

👉 🖼 ⚫️ 🔜 💎 🙅. ✋️ ➡️ 💬 👈 ↩️ ⚫️ 💰 ⏮️ 🎏 🏗 🏢, 👥 🚫🔜 🔀 ⚫️ & 🚮 `prefix`, `dependencies`, `tags`, ♒️. 🔗 `APIRouter`:

```Python hl_lines="3"
```Python hl_lines="3" title="app/internal/admin.py"
{!../../../docs_src/bigger_applications/app/internal/admin.py!}
```

✋️ 👥 💚 ⚒ 🛃 `prefix` 🕐❔ ✅ `APIRouter` 👈 🌐 🚮 *➡ 🛠️* ▶️ ⏮️ `/admin`, 👥 💚 🔐 ⚫️ ⏮️ `dependencies` 👥 ⏪ ✔️ 👉 🏗, & 👥 💚 🔌 `tags` & `responses`.

👥 💪 📣 🌐 👈 🍵 ✔️ 🔀 ⏮️ `APIRouter` 🚶‍♀️ 👈 🔢 `app.include_router()`:

```Python hl_lines="14-17"
```Python hl_lines="14-17" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```

Expand All @@ -432,7 +432,7 @@ from .routers.users import router

📥 👥 ⚫️... 🎦 👈 👥 💪 🤷:

```Python hl_lines="21-23"
```Python hl_lines="21-23" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```

Expand Down
30 changes: 15 additions & 15 deletions docs/en/docs/tutorial/bigger-applications.md
Expand Up @@ -79,7 +79,7 @@ You can create the *path operations* for that module using `APIRouter`.

You import it and create an "instance" the same way you would with the class `FastAPI`:

```Python hl_lines="1 3"
```Python hl_lines="1 3" title="app/routers/users.py"
{!../../../docs_src/bigger_applications/app/routers/users.py!}
```

Expand All @@ -89,7 +89,7 @@ And then you use it to declare your *path operations*.

Use it the same way you would use the `FastAPI` class:

```Python hl_lines="6 11 16"
```Python hl_lines="6 11 16" title="app/routers/users.py"
{!../../../docs_src/bigger_applications/app/routers/users.py!}
```

Expand All @@ -114,13 +114,13 @@ We will now use a simple dependency to read a custom `X-Token` header:

=== "Python 3.9+"

```Python hl_lines="3 6-8"
```Python hl_lines="3 6-8" title="app/dependencies.py"
{!> ../../../docs_src/bigger_applications/app_an_py39/dependencies.py!}
```

=== "Python 3.8+"

```Python hl_lines="1 5-7"
```Python hl_lines="1 5-7" title="app/dependencies.py"
{!> ../../../docs_src/bigger_applications/app_an/dependencies.py!}
```

Expand All @@ -129,7 +129,7 @@ We will now use a simple dependency to read a custom `X-Token` header:
!!! tip
Prefer to use the `Annotated` version if possible.

```Python hl_lines="1 4-6"
```Python hl_lines="1 4-6" title="app/dependencies.py"
{!> ../../../docs_src/bigger_applications/app/dependencies.py!}
```

Expand Down Expand Up @@ -160,7 +160,7 @@ We know all the *path operations* in this module have the same:

So, instead of adding all that to each *path operation*, we can add it to the `APIRouter`.

```Python hl_lines="5-10 16 21"
```Python hl_lines="5-10 16 21" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```

Expand Down Expand Up @@ -212,7 +212,7 @@ And we need to get the dependency function from the module `app.dependencies`, t

So we use a relative import with `..` for the dependencies:

```Python hl_lines="3"
```Python hl_lines="3" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```

Expand Down Expand Up @@ -282,7 +282,7 @@ We are not adding the prefix `/items` nor the `tags=["items"]` to each *path ope

But we can still add _more_ `tags` that will be applied to a specific *path operation*, and also some extra `responses` specific to that *path operation*:

```Python hl_lines="30-31"
```Python hl_lines="30-31" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```

Expand All @@ -307,15 +307,15 @@ You import and create a `FastAPI` class as normally.

And we can even declare [global dependencies](dependencies/global-dependencies.md){.internal-link target=_blank} that will be combined with the dependencies for each `APIRouter`:

```Python hl_lines="1 3 7"
```Python hl_lines="1 3 7" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```

### Import the `APIRouter`

Now we import the other submodules that have `APIRouter`s:

```Python hl_lines="5"
```Python hl_lines="5" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```

Expand Down Expand Up @@ -377,15 +377,15 @@ The `router` from `users` would overwrite the one from `items` and we wouldn't b

So, to be able to use both of them in the same file, we import the submodules directly:

```Python hl_lines="5"
```Python hl_lines="5" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```

### Include the `APIRouter`s for `users` and `items`

Now, let's include the `router`s from the submodules `users` and `items`:

```Python hl_lines="10-11"
```Python hl_lines="10-11" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```

Expand Down Expand Up @@ -418,15 +418,15 @@ It contains an `APIRouter` with some admin *path operations* that your organizat

For this example it will be super simple. But let's say that because it is shared with other projects in the organization, we cannot modify it and add a `prefix`, `dependencies`, `tags`, etc. directly to the `APIRouter`:

```Python hl_lines="3"
```Python hl_lines="3" title="app/internal/admin.py"
{!../../../docs_src/bigger_applications/app/internal/admin.py!}
```

But we still want to set a custom `prefix` when including the `APIRouter` so that all its *path operations* start with `/admin`, we want to secure it with the `dependencies` we already have for this project, and we want to include `tags` and `responses`.

We can declare all that without having to modify the original `APIRouter` by passing those parameters to `app.include_router()`:

```Python hl_lines="14-17"
```Python hl_lines="14-17" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```

Expand All @@ -449,7 +449,7 @@ We can also add *path operations* directly to the `FastAPI` app.

Here we do it... just to show that we can 🤷:

```Python hl_lines="21-23"
```Python hl_lines="21-23" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```

Expand Down
26 changes: 13 additions & 13 deletions docs/zh/docs/tutorial/bigger-applications.md
Expand Up @@ -79,7 +79,7 @@

你可以导入它并通过与 `FastAPI` 类相同的方式创建一个「实例」:

```Python hl_lines="1 3"
```Python hl_lines="1 3" title="app/routers/users.py"
{!../../../docs_src/bigger_applications/app/routers/users.py!}
```

Expand All @@ -89,7 +89,7 @@

使用方式与 `FastAPI` 类相同:

```Python hl_lines="6 11 16"
```Python hl_lines="6 11 16" title="app/routers/users.py"
{!../../../docs_src/bigger_applications/app/routers/users.py!}
```

Expand All @@ -112,7 +112,7 @@

现在我们将使用一个简单的依赖项来读取一个自定义的 `X-Token` 请求首部:

```Python hl_lines="1 4-6"
```Python hl_lines="1 4-6" title="app/dependencies.py"
{!../../../docs_src/bigger_applications/app/dependencies.py!}
```

Expand Down Expand Up @@ -143,7 +143,7 @@

因此,我们可以将其添加到 `APIRouter` 中,而不是将其添加到每个路径操作中。

```Python hl_lines="5-10 16 21"
```Python hl_lines="5-10 16 21" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```

Expand Down Expand Up @@ -195,7 +195,7 @@ async def read_item(item_id: str):

因此,我们通过 `..` 对依赖项使用了相对导入:

```Python hl_lines="3"
```Python hl_lines="3" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```

Expand Down Expand Up @@ -265,7 +265,7 @@ from ...dependencies import get_token_header

但是我们仍然可以添加*更多*将会应用于特定的*路径操作*`tags`,以及一些特定于该*路径操作*的额外 `responses`

```Python hl_lines="30-31"
```Python hl_lines="30-31" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```

Expand All @@ -290,15 +290,15 @@ from ...dependencies import get_token_header

我们甚至可以声明[全局依赖项](dependencies/global-dependencies.md){.internal-link target=_blank},它会和每个 `APIRouter` 的依赖项组合在一起:

```Python hl_lines="1 3 7"
```Python hl_lines="1 3 7" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```

### 导入 `APIRouter`

现在,我们导入具有 `APIRouter` 的其他子模块:

```Python hl_lines="5"
```Python hl_lines="5" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```

Expand Down Expand Up @@ -360,15 +360,15 @@ from .routers.users import router

因此,为了能够在同一个文件中使用它们,我们直接导入子模块:

```Python hl_lines="4"
```Python hl_lines="5" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```

### 包含 `users``items``APIRouter`

现在,让我们来包含来自 `users``items` 子模块的 `router`

```Python hl_lines="10-11"
```Python hl_lines="10-11" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```

Expand Down Expand Up @@ -401,15 +401,15 @@ from .routers.users import router

对于此示例,它将非常简单。但是假设由于它是与组织中的其他项目所共享的,因此我们无法对其进行修改,以及直接在 `APIRouter` 中添加 `prefix``dependencies``tags` 等:

```Python hl_lines="3"
```Python hl_lines="3" title="app/internal/admin.py"
{!../../../docs_src/bigger_applications/app/internal/admin.py!}
```

但是我们仍然希望在包含 `APIRouter` 时设置一个自定义的 `prefix`,以便其所有*路径操作*`/admin` 开头,我们希望使用本项目已经有的 `dependencies` 保护它,并且我们希望它包含自定义的 `tags``responses`

我们可以通过将这些参数传递给 `app.include_router()` 来完成所有的声明,而不必修改原始的 `APIRouter`

```Python hl_lines="14-17"
```Python hl_lines="14-17" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```

Expand All @@ -432,7 +432,7 @@ from .routers.users import router

这里我们这样做了...只是为了表明我们可以做到🤷:

```Python hl_lines="21-23"
```Python hl_lines="21-23" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```

Expand Down

0 comments on commit 6bda132

Please sign in to comment.