Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

📝 Update includes indocs/en/docs/tutorial/body-multiple-params.md#12593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
220 changes: 6 additions & 214 deletionsdocs/en/docs/tutorial/body-multiple-params.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,57 +8,9 @@ First, of course, you can mix `Path`, `Query` and request body parameter declara

And you can also declare body parameters as optional, by setting the default to `None`:

//// tab | Python 3.10+
{* ../../docs_src/body_multiple_params/tutorial001_an_py310.py hl[18:20] *}

```Python hl_lines="18-20"
{!> ../../docs_src/body_multiple_params/tutorial001_an_py310.py!}
```

////

//// tab | Python 3.9+

```Python hl_lines="18-20"
{!> ../../docs_src/body_multiple_params/tutorial001_an_py39.py!}
```

////

//// tab | Python 3.8+

```Python hl_lines="19-21"
{!> ../../docs_src/body_multiple_params/tutorial001_an.py!}
```

////

//// tab | Python 3.10+ non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///

```Python hl_lines="17-19"
{!> ../../docs_src/body_multiple_params/tutorial001_py310.py!}
```

////

//// tab | Python 3.8+ non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///

```Python hl_lines="19-21"
{!> ../../docs_src/body_multiple_params/tutorial001.py!}
```

////
## Multiple body parameters

/// note

Expand All@@ -81,21 +33,8 @@ In the previous example, the *path operations* would expect a JSON body with the

But you can also declare multiple body parameters, e.g. `item` and `user`:

//// tab | Python 3.10+

```Python hl_lines="20"
{!> ../../docs_src/body_multiple_params/tutorial002_py310.py!}
```

////
{* ../../docs_src/body_multiple_params/tutorial002_py310.py hl[20] *}

//// tab | Python 3.8+

```Python hl_lines="22"
{!> ../../docs_src/body_multiple_params/tutorial002.py!}
```

////

In this case, **FastAPI** will notice that there is more than one body parameter in the function (there are two parameters that are Pydantic models).

Expand DownExpand Up@@ -136,57 +75,8 @@ If you declare it as is, because it is a singular value, **FastAPI** will assume

But you can instruct **FastAPI** to treat it as another body key using `Body`:

//// tab | Python 3.10+

```Python hl_lines="23"
{!> ../../docs_src/body_multiple_params/tutorial003_an_py310.py!}
```

////

//// tab | Python 3.9+

```Python hl_lines="23"
{!> ../../docs_src/body_multiple_params/tutorial003_an_py39.py!}
```

////

//// tab | Python 3.8+

```Python hl_lines="24"
{!> ../../docs_src/body_multiple_params/tutorial003_an.py!}
```

////

//// tab | Python 3.10+ non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///
{* ../../docs_src/body_multiple_params/tutorial003_an_py310.py hl[23] *}

```Python hl_lines="20"
{!> ../../docs_src/body_multiple_params/tutorial003_py310.py!}
```

////

//// tab | Python 3.8+ non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///

```Python hl_lines="22"
{!> ../../docs_src/body_multiple_params/tutorial003.py!}
```

////

In this case, **FastAPI** will expect a body like:

Expand DownExpand Up@@ -226,57 +116,8 @@ q: str | None = None

For example:

//// tab | Python 3.10+

```Python hl_lines="28"
{!> ../../docs_src/body_multiple_params/tutorial004_an_py310.py!}
```

////

//// tab | Python 3.9+

```Python hl_lines="28"
{!> ../../docs_src/body_multiple_params/tutorial004_an_py39.py!}
```

////

//// tab | Python 3.8+

```Python hl_lines="29"
{!> ../../docs_src/body_multiple_params/tutorial004_an.py!}
```

////
{* ../../docs_src/body_multiple_params/tutorial004_an_py310.py hl[28] *}

//// tab | Python 3.10+ non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///

```Python hl_lines="26"
{!> ../../docs_src/body_multiple_params/tutorial004_py310.py!}
```

////

//// tab | Python 3.8+ non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///

```Python hl_lines="28"
{!> ../../docs_src/body_multiple_params/tutorial004.py!}
```

////

/// info

Expand All@@ -298,57 +139,8 @@ item: Item = Body(embed=True)

as in:

//// tab | Python 3.10+

```Python hl_lines="17"
{!> ../../docs_src/body_multiple_params/tutorial005_an_py310.py!}
```

////

//// tab | Python 3.9+

```Python hl_lines="17"
{!> ../../docs_src/body_multiple_params/tutorial005_an_py39.py!}
```

////

//// tab | Python 3.8+

```Python hl_lines="18"
{!> ../../docs_src/body_multiple_params/tutorial005_an.py!}
```

////

//// tab | Python 3.10+ non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///

```Python hl_lines="15"
{!> ../../docs_src/body_multiple_params/tutorial005_py310.py!}
```

////

//// tab | Python 3.8+ non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///

```Python hl_lines="17"
{!> ../../docs_src/body_multiple_params/tutorial005.py!}
```
{* ../../docs_src/body_multiple_params/tutorial005_an_py310.py hl[17] *}

////

In this case **FastAPI** will expect a body like:

Expand Down

[8]ページ先頭

©2009-2026 Movatter.jp