mirror of
https://github.com/fastapi/fastapi.git
synced 2026-06-15 11:01:13 -04:00
Compare commits
1 Commits
translate-
...
translate-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
479d699ab7 |
@@ -192,7 +192,7 @@ $ pip install "fastapi[standard]"
|
||||
|
||||
</div>
|
||||
|
||||
**Hinweis**: Stellen Sie sicher, dass Sie `"fastapi[standard]"` in Anführungszeichen setzen, damit es in allen Terminals funktioniert.
|
||||
**Hinweis**: Stellen Sie sicher, dass Sie „fastapi[standard]“ in Anführungszeichen setzen, damit es in allen Terminals funktioniert.
|
||||
|
||||
## Beispiel { #example }
|
||||
|
||||
@@ -492,9 +492,7 @@ Für ein vollständigeres Beispiel, mit weiteren Funktionen, siehe das <a href="
|
||||
|
||||
### Ihre App deployen (optional) { #deploy-your-app-optional }
|
||||
|
||||
Optional können Sie Ihre FastAPI-App in die [FastAPI Cloud](https://fastapicloud.com) deployen, gehen Sie und treten Sie der Warteliste bei, falls noch nicht geschehen. 🚀
|
||||
|
||||
Wenn Sie bereits ein **FastAPI Cloud**-Konto haben (wir haben Sie von der Warteliste eingeladen 😉), können Sie Ihre Anwendung mit einem einzigen Befehl deployen.
|
||||
Optional können Sie Ihre FastAPI-App mit einem einzigen Befehl in die [FastAPI Cloud](https://fastapicloud.com) deployen. 🚀
|
||||
|
||||
<div class="termy">
|
||||
|
||||
@@ -510,6 +508,8 @@ Deploying to FastAPI Cloud...
|
||||
|
||||
</div>
|
||||
|
||||
Das CLI erkennt Ihre FastAPI-Anwendung automatisch und deployt sie in die Cloud. Wenn Sie nicht eingeloggt sind, wird Ihr Browser geöffnet, um den Authentifizierungsprozess abzuschließen.
|
||||
|
||||
Das war’s! Jetzt können Sie unter dieser URL auf Ihre App zugreifen. ✨
|
||||
|
||||
#### Über FastAPI Cloud { #about-fastapi-cloud }
|
||||
|
||||
@@ -108,7 +108,7 @@ Zum Beispiel:
|
||||
|
||||
{* ../../docs_src/body_multiple_params/tutorial004_an_py310.py hl[28] *}
|
||||
|
||||
/// info | Info
|
||||
/// note | Hinweis
|
||||
|
||||
`Body` hat die gleichen zusätzlichen Validierungs- und Metadaten-Parameter wie `Query`, `Path` und andere, die Sie später kennenlernen werden.
|
||||
|
||||
@@ -123,7 +123,7 @@ Standardmäßig wird **FastAPI** dann seinen Body direkt erwarten.
|
||||
Aber wenn Sie möchten, dass es einen JSON-Body mit einem Schlüssel `item` erwartet, und darin den Inhalt des Modells, so wie es das tut, wenn Sie mehrere Body-Parameter deklarieren, dann können Sie den speziellen `Body`-Parameter `embed` setzen:
|
||||
|
||||
```Python
|
||||
item: Item = Body(embed=True)
|
||||
item: Annotated[Item, Body(embed=True)]
|
||||
```
|
||||
|
||||
so wie in:
|
||||
|
||||
@@ -8,7 +8,7 @@ Ihre API muss fast immer einen **Response**body senden. Aber Clients müssen nic
|
||||
|
||||
Um einen **Request**body zu deklarieren, verwenden Sie [Pydantic](https://docs.pydantic.dev/)-Modelle mit all deren Fähigkeiten und Vorzügen.
|
||||
|
||||
/// info | Info
|
||||
/// note | Hinweis
|
||||
|
||||
Um Daten zu senden, sollten Sie eines von: `POST` (meistverwendet), `PUT`, `DELETE` oder `PATCH` verwenden.
|
||||
|
||||
|
||||
@@ -24,13 +24,13 @@ Aber denken Sie daran, dass, wenn Sie `Query`, `Path`, `Cookie` und andere von `
|
||||
|
||||
///
|
||||
|
||||
/// info | Info
|
||||
/// note | Hinweis
|
||||
|
||||
Um Cookies zu deklarieren, müssen Sie `Cookie` verwenden, da die Parameter sonst als Query-Parameter interpretiert würden.
|
||||
|
||||
///
|
||||
|
||||
/// info | Info
|
||||
/// note | Hinweis
|
||||
|
||||
Beachten Sie, dass **Browser Cookies auf besondere Weise und hinter den Kulissen handhaben** und **JavaScript** **nicht** ohne Weiteres erlauben, auf sie zuzugreifen.
|
||||
|
||||
|
||||
@@ -72,13 +72,13 @@ Sie können die Response mit dem Parameter `response_description` beschreiben:
|
||||
|
||||
{* ../../docs_src/path_operation_configuration/tutorial005_py310.py hl[18] *}
|
||||
|
||||
/// info | Info
|
||||
/// note | Hinweis
|
||||
|
||||
Beachten Sie, dass sich `response_description` speziell auf die Response bezieht, während `description` sich generell auf die *Pfadoperation* bezieht.
|
||||
|
||||
///
|
||||
|
||||
/// check | Testen
|
||||
/// tip | Tipp
|
||||
|
||||
OpenAPI verlangt, dass jede *Pfadoperation* über eine Beschreibung der Response verfügt.
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ Importieren Sie zuerst `Path` von `fastapi`, und importieren Sie `Annotated`:
|
||||
|
||||
{* ../../docs_src/path_params_numeric_validations/tutorial001_an_py310.py hl[1,3] *}
|
||||
|
||||
/// info | Info
|
||||
/// note | Hinweis
|
||||
|
||||
FastAPI hat in Version 0.95.0 Unterstützung für `Annotated` hinzugefügt und es zur Verwendung empfohlen.
|
||||
|
||||
@@ -131,7 +131,7 @@ Und Sie können auch Zahlenvalidierungen deklarieren:
|
||||
* `lt`: `l`ess `t`han (kleiner als)
|
||||
* `le`: `l`ess than or `e`qual (kleiner oder gleich)
|
||||
|
||||
/// info | Info
|
||||
/// note | Hinweis
|
||||
|
||||
`Query`, `Path`, und andere Klassen, die Sie später sehen werden, sind Unterklassen einer gemeinsamen `Param`-Klasse.
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Sie können Dateien, die vom Client hochgeladen werden, mithilfe von `File` definieren.
|
||||
|
||||
/// info | Info
|
||||
/// note | Hinweis
|
||||
|
||||
Um hochgeladene Dateien zu empfangen, installieren Sie zuerst [`python-multipart`](https://github.com/Kludex/python-multipart).
|
||||
|
||||
@@ -28,7 +28,7 @@ Erstellen Sie Datei-Parameter, so wie Sie es auch mit `Body` und `Form` machen w
|
||||
|
||||
{* ../../docs_src/request_files/tutorial001_an_py310.py hl[9] *}
|
||||
|
||||
/// info | Info
|
||||
/// note | Hinweis
|
||||
|
||||
`File` ist eine Klasse, die direkt von `Form` erbt.
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Sie können gleichzeitig Dateien und Formulardaten mit `File` und `Form` definieren.
|
||||
|
||||
/// info | Info
|
||||
/// note | Hinweis
|
||||
|
||||
Um hochgeladene Dateien und/oder Formulardaten zu empfangen, installieren Sie zuerst [`python-multipart`](https://github.com/Kludex/python-multipart).
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ Beachten Sie, dass `status_code` ein Parameter der „Dekorator“-Methode ist (
|
||||
|
||||
Dem `status_code`-Parameter wird eine Zahl mit dem HTTP-Statuscode übergeben.
|
||||
|
||||
/// info | Info
|
||||
/// note | Hinweis
|
||||
|
||||
Alternativ kann `status_code` auch ein `IntEnum` erhalten, wie etwa Pythons [`http.HTTPStatus`](https://docs.python.org/3/library/http.html#http.HTTPStatus).
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ Damit können Sie [pytest](https://docs.pytest.org/) direkt mit **FastAPI** verw
|
||||
|
||||
## `TestClient` verwenden { #using-testclient }
|
||||
|
||||
/// info | Info
|
||||
/// note | Hinweis
|
||||
|
||||
Um `TestClient` zu verwenden, installieren Sie zunächst [`httpx`](https://www.python-httpx.org).
|
||||
|
||||
@@ -145,7 +145,7 @@ Z. B.:
|
||||
|
||||
Weitere Informationen zum Übergeben von Daten an das Backend (mithilfe von `httpx` oder dem `TestClient`) finden Sie in der [HTTPX-Dokumentation](https://www.python-httpx.org).
|
||||
|
||||
/// info | Info
|
||||
/// note | Hinweis
|
||||
|
||||
Beachten Sie, dass der `TestClient` Daten empfängt, die nach JSON konvertiert werden können, keine Pydantic-Modelle.
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ Les principales fonctionnalités sont :
|
||||
|
||||
---
|
||||
|
||||
« _Si quelqu’un cherche à construire une API Python de production, je recommande vivement **FastAPI**. Il est **magnifiquement conçu**, **simple à utiliser** et **hautement scalable**, il est devenu un **composant clé** de notre stratégie de développement API-first et alimente de nombreuses automatisations et services tels que notre Virtual TAC Engineer._ »
|
||||
« _Si quelqu’un cherche à construire une API Python de production, je recommande vivement **FastAPI**. Il est **magnifiquement conçu**, **simple à utiliser** et **hautement scalable** — il est devenu un **composant clé** de notre stratégie de développement API-first._ »
|
||||
|
||||
<div style="text-align: right; margin-right: 10%;">Deon Pillsbury - <strong>Cisco</strong> <a href="https://www.linkedin.com/posts/deonpillsbury_cisco-cx-python-activity-6963242628536487936-trAp/"><small>(ref)</small></a></div>
|
||||
|
||||
@@ -492,7 +492,9 @@ Pour un exemple plus complet comprenant plus de fonctionnalités, voir le <a hre
|
||||
|
||||
### Déployer votre application (optionnel) { #deploy-your-app-optional }
|
||||
|
||||
Vous pouvez, si vous le souhaitez, déployer votre application FastAPI sur [FastAPI Cloud](https://fastapicloud.com) avec une seule commande. 🚀
|
||||
Vous pouvez, si vous le souhaitez, déployer votre application FastAPI sur [FastAPI Cloud](https://fastapicloud.com), allez vous inscrire sur la liste d'attente si ce n'est pas déjà fait. 🚀
|
||||
|
||||
Si vous avez déjà un compte **FastAPI Cloud** (nous vous avons invité depuis la liste d'attente 😉), vous pouvez déployer votre application avec une seule commande.
|
||||
|
||||
<div class="termy">
|
||||
|
||||
@@ -508,8 +510,6 @@ Deploying to FastAPI Cloud...
|
||||
|
||||
</div>
|
||||
|
||||
La CLI détectera automatiquement votre application FastAPI et la déploiera dans le cloud. Si vous n'êtes pas connecté, votre navigateur s'ouvrira pour terminer le processus d'authentification.
|
||||
|
||||
C'est tout ! Vous pouvez maintenant accéder à votre application à cette URL. ✨
|
||||
|
||||
#### À propos de FastAPI Cloud { #about-fastapi-cloud }
|
||||
|
||||
@@ -108,7 +108,7 @@ Par exemple :
|
||||
|
||||
{* ../../docs_src/body_multiple_params/tutorial004_an_py310.py hl[28] *}
|
||||
|
||||
/// note | Remarque
|
||||
/// info
|
||||
|
||||
`Body` possède également les mêmes paramètres supplémentaires de validation et de métadonnées que `Query`, `Path` et d'autres que vous verrez plus tard.
|
||||
|
||||
@@ -123,7 +123,7 @@ Par défaut, **FastAPI** attendra alors son contenu directement.
|
||||
Mais si vous voulez qu'il attende un JSON avec une clé `item` contenant le contenu du modèle, comme lorsqu'on déclare des paramètres supplémentaires du corps de la requête, vous pouvez utiliser le paramètre spécial `embed` de `Body` :
|
||||
|
||||
```Python
|
||||
item: Annotated[Item, Body(embed=True)]
|
||||
item: Item = Body(embed=True)
|
||||
```
|
||||
|
||||
comme dans :
|
||||
|
||||
@@ -24,13 +24,13 @@ Mais rappelez-vous que lorsque vous importez `Query`, `Path`, `Cookie` et d'autr
|
||||
|
||||
///
|
||||
|
||||
/// note | Remarque
|
||||
/// info
|
||||
|
||||
Pour déclarer des cookies, vous devez utiliser `Cookie`, sinon les paramètres seraient interprétés comme des paramètres de requête.
|
||||
|
||||
///
|
||||
|
||||
/// note | Remarque
|
||||
/// info
|
||||
|
||||
Gardez à l'esprit que, comme **les navigateurs gèrent les cookies** de manière particulière et en coulisses, ils **n'autorisent pas** facilement **JavaScript** à y accéder.
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ Ainsi, la ligne :
|
||||
|
||||
ne sera pas exécutée.
|
||||
|
||||
/// note | Remarque
|
||||
/// info
|
||||
|
||||
Pour plus d'informations, consultez [la documentation officielle de Python](https://docs.python.org/3/library/__main__.html).
|
||||
|
||||
|
||||
@@ -72,13 +72,13 @@ Vous pouvez spécifier la description de la réponse avec le paramètre `respons
|
||||
|
||||
{* ../../docs_src/path_operation_configuration/tutorial005_py310.py hl[18] *}
|
||||
|
||||
/// note | Remarque
|
||||
/// info
|
||||
|
||||
Notez que `response_description` se réfère spécifiquement à la réponse, tandis que `description` se réfère au *chemin d'accès* en général.
|
||||
|
||||
///
|
||||
|
||||
/// tip | Astuce
|
||||
/// check | Vérifications
|
||||
|
||||
OpenAPI spécifie que chaque *chemin d'accès* requiert une description de réponse.
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ Tout d'abord, importez `Path` de `fastapi`, et importez `Annotated` :
|
||||
|
||||
{* ../../docs_src/path_params_numeric_validations/tutorial001_an_py310.py hl[1,3] *}
|
||||
|
||||
/// note | Remarque
|
||||
/// info
|
||||
|
||||
FastAPI a ajouté le support pour `Annotated` (et a commencé à le recommander) dans la version 0.95.0.
|
||||
|
||||
@@ -131,7 +131,7 @@ Et vous pouvez également déclarer des validations numériques :
|
||||
* `lt` : `l`ess `t`han
|
||||
* `le` : `l`ess than or `e`qual
|
||||
|
||||
/// note | Remarque
|
||||
/// info
|
||||
|
||||
`Query`, `Path`, et d'autres classes que vous verrez plus tard sont des sous-classes d'une classe commune `Param`.
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Vous pouvez définir des fichiers à téléverser par le client en utilisant `File`.
|
||||
|
||||
/// note | Remarque
|
||||
/// info
|
||||
|
||||
Pour recevoir des fichiers téléversés, installez d'abord [`python-multipart`](https://github.com/Kludex/python-multipart).
|
||||
|
||||
@@ -28,7 +28,7 @@ Créez des paramètres de fichier de la même manière que pour `Body` ou `Form`
|
||||
|
||||
{* ../../docs_src/request_files/tutorial001_an_py310.py hl[9] *}
|
||||
|
||||
/// note | Remarque
|
||||
/// info
|
||||
|
||||
`File` est une classe qui hérite directement de `Form`.
|
||||
|
||||
@@ -44,7 +44,7 @@ Pour déclarer des fichiers dans le corps de la requête, vous devez utiliser `F
|
||||
|
||||
Les fichiers seront téléversés en « données de formulaire ».
|
||||
|
||||
Si vous déclarez le type de votre *fonction de chemin d'accès* comme `bytes`, **FastAPI** lira le fichier pour vous et vous recevrez le contenu sous forme de `bytes`.
|
||||
Si vous déclarez le type de votre paramètre de *fonction de chemin d'accès* comme `bytes`, **FastAPI** lira le fichier pour vous et vous recevrez le contenu sous forme de `bytes`.
|
||||
|
||||
Gardez à l'esprit que cela signifie que tout le contenu sera stocké en mémoire. Cela fonctionnera bien pour de petits fichiers.
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Vous pouvez définir des fichiers et des champs de formulaire en même temps à l'aide de `File` et `Form`.
|
||||
|
||||
/// note | Remarque
|
||||
/// info
|
||||
|
||||
Pour recevoir des fichiers téléversés et/ou des données de formulaire, installez d'abord [`python-multipart`](https://github.com/Kludex/python-multipart).
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ Remarquez que `status_code` est un paramètre de la méthode « decorator » (`g
|
||||
|
||||
Le paramètre `status_code` reçoit un nombre correspondant au code d'état HTTP.
|
||||
|
||||
/// note | Remarque
|
||||
/// info
|
||||
|
||||
`status_code` peut aussi recevoir un `IntEnum`, comme le [`http.HTTPStatus`](https://docs.python.org/3/library/http.html#http.HTTPStatus) de Python.
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ Avec cela, vous pouvez utiliser [pytest](https://docs.pytest.org/) directement a
|
||||
|
||||
## Utiliser `TestClient` { #using-testclient }
|
||||
|
||||
/// note | Remarque
|
||||
/// info
|
||||
|
||||
Pour utiliser `TestClient`, installez d’abord [`httpx`](https://www.python-httpx.org).
|
||||
|
||||
@@ -144,7 +144,7 @@ Par exemple :
|
||||
|
||||
Pour plus d’informations sur la manière de transmettre des données au backend (en utilisant `httpx` ou le `TestClient`), consultez la [documentation HTTPX](https://www.python-httpx.org).
|
||||
|
||||
/// note | Remarque
|
||||
/// info
|
||||
|
||||
Notez que le `TestClient` reçoit des données qui peuvent être converties en JSON, pas des modèles Pydantic.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user