|
|
@ -8,57 +8,7 @@ Zuerst einmal, Sie können `Path`-, `Query`- und Requestbody-Parameter-Deklarati |
|
|
|
|
|
|
|
Und Sie können auch Body-Parameter als optional kennzeichnen, indem Sie den Defaultwert auf `None` setzen: |
|
|
|
|
|
|
|
//// tab | Python 3.10+ |
|
|
|
|
|
|
|
```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+ nicht annotiert |
|
|
|
|
|
|
|
/// tip | "Tipp" |
|
|
|
|
|
|
|
Bevorzugen Sie die `Annotated`-Version, falls möglich. |
|
|
|
|
|
|
|
/// |
|
|
|
|
|
|
|
```Python hl_lines="17-19" |
|
|
|
{!> ../../docs_src/body_multiple_params/tutorial001_py310.py!} |
|
|
|
``` |
|
|
|
|
|
|
|
//// |
|
|
|
|
|
|
|
//// tab | Python 3.8+ nicht annotiert |
|
|
|
|
|
|
|
/// tip | "Tipp" |
|
|
|
|
|
|
|
Bevorzugen Sie die `Annotated`-Version, falls möglich. |
|
|
|
|
|
|
|
/// |
|
|
|
|
|
|
|
```Python hl_lines="19-21" |
|
|
|
{!> ../../docs_src/body_multiple_params/tutorial001.py!} |
|
|
|
``` |
|
|
|
|
|
|
|
//// |
|
|
|
{* ../../docs_src/body_multiple_params/tutorial001_an_py310.py hl[18:20] *} |
|
|
|
|
|
|
|
/// note | "Hinweis" |
|
|
|
|
|
|
@ -81,21 +31,7 @@ Im vorherigen Beispiel erwartete die *Pfadoperation* einen JSON-Body mit den Att |
|
|
|
|
|
|
|
Aber Sie können auch mehrere Body-Parameter deklarieren, z. B. `item` und `user`: |
|
|
|
|
|
|
|
//// tab | Python 3.10+ |
|
|
|
|
|
|
|
```Python hl_lines="20" |
|
|
|
{!> ../../docs_src/body_multiple_params/tutorial002_py310.py!} |
|
|
|
``` |
|
|
|
|
|
|
|
//// |
|
|
|
|
|
|
|
//// tab | Python 3.8+ |
|
|
|
|
|
|
|
```Python hl_lines="22" |
|
|
|
{!> ../../docs_src/body_multiple_params/tutorial002.py!} |
|
|
|
``` |
|
|
|
|
|
|
|
//// |
|
|
|
{* ../../docs_src/body_multiple_params/tutorial002_py310.py hl[20] *} |
|
|
|
|
|
|
|
In diesem Fall wird **FastAPI** bemerken, dass es mehr als einen Body-Parameter in der Funktion gibt (zwei Parameter, die Pydantic-Modelle sind). |
|
|
|
|
|
|
@ -136,57 +72,7 @@ Wenn Sie diesen Parameter einfach so hinzufügen, wird **FastAPI** annehmen, das |
|
|
|
|
|
|
|
Aber Sie können **FastAPI** instruieren, ihn als weiteren Body-Schlüssel zu erkennen, indem Sie `Body` verwenden: |
|
|
|
|
|
|
|
//// 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+ nicht annotiert |
|
|
|
|
|
|
|
/// tip | "Tipp" |
|
|
|
|
|
|
|
Bevorzugen Sie die `Annotated`-Version, falls möglich. |
|
|
|
|
|
|
|
/// |
|
|
|
|
|
|
|
```Python hl_lines="20" |
|
|
|
{!> ../../docs_src/body_multiple_params/tutorial003_py310.py!} |
|
|
|
``` |
|
|
|
|
|
|
|
//// |
|
|
|
|
|
|
|
//// tab | Python 3.8+ nicht annotiert |
|
|
|
|
|
|
|
/// tip | "Tipp" |
|
|
|
|
|
|
|
Bevorzugen Sie die `Annotated`-Version, falls möglich. |
|
|
|
|
|
|
|
/// |
|
|
|
|
|
|
|
```Python hl_lines="22" |
|
|
|
{!> ../../docs_src/body_multiple_params/tutorial003.py!} |
|
|
|
``` |
|
|
|
|
|
|
|
//// |
|
|
|
{* ../../docs_src/body_multiple_params/tutorial003_an_py310.py hl[23] *} |
|
|
|
|
|
|
|
In diesem Fall erwartet **FastAPI** einen Body wie: |
|
|
|
|
|
|
@ -226,57 +112,7 @@ q: str | None = None |
|
|
|
|
|
|
|
Zum Beispiel: |
|
|
|
|
|
|
|
//// tab | Python 3.10+ |
|
|
|
|
|
|
|
```Python hl_lines="27" |
|
|
|
{!> ../../docs_src/body_multiple_params/tutorial004_an_py310.py!} |
|
|
|
``` |
|
|
|
|
|
|
|
//// |
|
|
|
|
|
|
|
//// tab | Python 3.9+ |
|
|
|
|
|
|
|
```Python hl_lines="27" |
|
|
|
{!> ../../docs_src/body_multiple_params/tutorial004_an_py39.py!} |
|
|
|
``` |
|
|
|
|
|
|
|
//// |
|
|
|
|
|
|
|
//// tab | Python 3.8+ |
|
|
|
|
|
|
|
```Python hl_lines="28" |
|
|
|
{!> ../../docs_src/body_multiple_params/tutorial004_an.py!} |
|
|
|
``` |
|
|
|
|
|
|
|
//// |
|
|
|
|
|
|
|
//// tab | Python 3.10+ nicht annotiert |
|
|
|
|
|
|
|
/// tip | "Tipp" |
|
|
|
|
|
|
|
Bevorzugen Sie die `Annotated`-Version, falls möglich. |
|
|
|
|
|
|
|
/// |
|
|
|
|
|
|
|
```Python hl_lines="25" |
|
|
|
{!> ../../docs_src/body_multiple_params/tutorial004_py310.py!} |
|
|
|
``` |
|
|
|
|
|
|
|
//// |
|
|
|
|
|
|
|
//// tab | Python 3.8+ nicht annotiert |
|
|
|
|
|
|
|
/// tip | "Tipp" |
|
|
|
|
|
|
|
Bevorzugen Sie die `Annotated`-Version, falls möglich. |
|
|
|
|
|
|
|
/// |
|
|
|
|
|
|
|
```Python hl_lines="27" |
|
|
|
{!> ../../docs_src/body_multiple_params/tutorial004.py!} |
|
|
|
``` |
|
|
|
|
|
|
|
//// |
|
|
|
{* ../../docs_src/body_multiple_params/tutorial004_an_py310.py hl[27] *} |
|
|
|
|
|
|
|
/// info |
|
|
|
|
|
|
@ -298,57 +134,7 @@ item: Item = Body(embed=True) |
|
|
|
|
|
|
|
so wie 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+ nicht annotiert |
|
|
|
|
|
|
|
/// tip | "Tipp" |
|
|
|
|
|
|
|
Bevorzugen Sie die `Annotated`-Version, falls möglich. |
|
|
|
|
|
|
|
/// |
|
|
|
|
|
|
|
```Python hl_lines="15" |
|
|
|
{!> ../../docs_src/body_multiple_params/tutorial005_py310.py!} |
|
|
|
``` |
|
|
|
|
|
|
|
//// |
|
|
|
|
|
|
|
//// tab | Python 3.8+ nicht annotiert |
|
|
|
|
|
|
|
/// tip | "Tipp" |
|
|
|
|
|
|
|
Bevorzugen Sie die `Annotated`-Version, falls möglich. |
|
|
|
|
|
|
|
/// |
|
|
|
|
|
|
|
```Python hl_lines="17" |
|
|
|
{!> ../../docs_src/body_multiple_params/tutorial005.py!} |
|
|
|
``` |
|
|
|
|
|
|
|
//// |
|
|
|
{* ../../docs_src/body_multiple_params/tutorial005_an_py310.py hl[17] *} |
|
|
|
|
|
|
|
In diesem Fall erwartet **FastAPI** einen Body wie: |
|
|
|
|
|
|
|