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.
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ Las funcionalidades clave son:
|
||||
* **Rápido**: Muy alto rendimiento, a la par con **NodeJS** y **Go** (gracias a Starlette y Pydantic). [Uno de los frameworks Python más rápidos disponibles](#performance).
|
||||
* **Rápido de programar**: Aumenta la velocidad para desarrollar funcionalidades en aproximadamente un 200% a 300%. *
|
||||
* **Menos bugs**: Reduce en aproximadamente un 40% los errores inducidos por humanos (desarrolladores). *
|
||||
* **Intuitivo**: Gran soporte para editores. <dfn title="también conocido como: autocompletado, IntelliSense">Autocompletado</dfn> en todas partes. Menos tiempo depurando.
|
||||
* **Intuitivo**: Gran soporte para editores. <dfn title="también conocido como: auto-complete, autocompletado, IntelliSense">Autocompletado</dfn> en todas partes. Menos tiempo depurando.
|
||||
* **Fácil**: Diseñado para ser fácil de usar y aprender. Menos tiempo leyendo documentación.
|
||||
* **Corto**: Minimiza la duplicación de código. Múltiples funcionalidades desde cada declaración de parámetro. Menos bugs.
|
||||
* **Robusto**: Obtén código listo para producción. Con documentación interactiva automática.
|
||||
@@ -492,7 +492,9 @@ Para un ejemplo más completo incluyendo más funcionalidades, ve al <a href="ht
|
||||
|
||||
### Despliega tu app (opcional) { #deploy-your-app-optional }
|
||||
|
||||
Opcionalmente puedes desplegar tu app de FastAPI en [FastAPI Cloud](https://fastapicloud.com) con un solo comando. 🚀
|
||||
Opcionalmente puedes desplegar tu app de FastAPI en [FastAPI Cloud](https://fastapicloud.com), ve y únete a la lista de espera si no lo has hecho. 🚀
|
||||
|
||||
Si ya tienes una cuenta de **FastAPI Cloud** (te invitamos desde la lista de espera 😉), puedes desplegar tu aplicación con un solo comando.
|
||||
|
||||
<div class="termy">
|
||||
|
||||
@@ -508,8 +510,6 @@ Deploying to FastAPI Cloud...
|
||||
|
||||
</div>
|
||||
|
||||
La CLI detectará automáticamente tu aplicación de FastAPI y la desplegará en la nube. Si no has iniciado sesión, se abrirá tu navegador para completar el proceso de autenticación.
|
||||
|
||||
¡Eso es todo! Ahora puedes acceder a tu app en esa URL. ✨
|
||||
|
||||
#### Acerca de FastAPI Cloud { #about-fastapi-cloud }
|
||||
|
||||
@@ -108,7 +108,7 @@ Por ejemplo:
|
||||
|
||||
{* ../../docs_src/body_multiple_params/tutorial004_an_py310.py hl[28] *}
|
||||
|
||||
/// note | Nota
|
||||
/// info | Información
|
||||
|
||||
`Body` también tiene todos los mismos parámetros de validación y metadatos extras que `Query`, `Path` y otros que verás luego.
|
||||
|
||||
@@ -123,7 +123,7 @@ Por defecto, **FastAPI** esperará su cuerpo directamente.
|
||||
Pero si deseas que espere un JSON con una clave `item` y dentro de ella los contenidos del modelo, como lo hace cuando declaras parámetros de cuerpo extra, puedes usar el parámetro especial `Body` `embed`:
|
||||
|
||||
```Python
|
||||
item: Annotated[Item, Body(embed=True)]
|
||||
item: Item = Body(embed=True)
|
||||
```
|
||||
|
||||
como en:
|
||||
|
||||
@@ -24,13 +24,13 @@ Pero recuerda que cuando importas `Query`, `Path`, `Cookie` y otros desde `fasta
|
||||
|
||||
///
|
||||
|
||||
/// note | Nota
|
||||
/// info | Información
|
||||
|
||||
Para declarar cookies, necesitas usar `Cookie`, porque de lo contrario los parámetros serían interpretados como parámetros de query.
|
||||
|
||||
///
|
||||
|
||||
/// note | Nota
|
||||
/// info | Información
|
||||
|
||||
Ten en cuenta que, como **los navegadores manejan las cookies** de formas especiales y por detrás, **no** permiten fácilmente que **JavaScript** las toque.
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ from myapp import app
|
||||
# Algún código adicional
|
||||
```
|
||||
|
||||
en ese caso, la variable creada automáticamente `__name__` dentro de `myapp.py` no tendrá el valor `"__main__"`.
|
||||
en ese caso, la variable creada automáticamente dentro de `myapp.py` no tendrá la variable `__name__` con un valor de `"__main__"`.
|
||||
|
||||
Así que, la línea:
|
||||
|
||||
@@ -72,7 +72,7 @@ Así que, la línea:
|
||||
|
||||
no se ejecutará.
|
||||
|
||||
/// note | Nota
|
||||
/// info | Información
|
||||
|
||||
Para más información, revisa [la documentación oficial de Python](https://docs.python.org/3/library/__main__.html).
|
||||
|
||||
@@ -88,7 +88,7 @@ Por ejemplo, en Visual Studio Code, puedes:
|
||||
|
||||
* Ir al panel de "Debug".
|
||||
* "Add configuration...".
|
||||
* Seleccionar "Python"
|
||||
* Seleccionar "Python".
|
||||
* Ejecutar el depurador con la opción "`Python: Current File (Integrated Terminal)`".
|
||||
|
||||
Luego, iniciará el servidor con tu código **FastAPI**, deteniéndose en tus puntos de interrupción, etc.
|
||||
|
||||
@@ -72,13 +72,13 @@ Puedes especificar la descripción del response con el parámetro `response_desc
|
||||
|
||||
{* ../../docs_src/path_operation_configuration/tutorial005_py310.py hl[18] *}
|
||||
|
||||
/// note | Nota
|
||||
/// info | Información
|
||||
|
||||
Ten en cuenta que `response_description` se refiere específicamente al response, mientras que `description` se refiere a la *path operation* en general.
|
||||
|
||||
///
|
||||
|
||||
/// tip | Consejo
|
||||
/// check | Revisa
|
||||
|
||||
OpenAPI especifica que cada *path operation* requiere una descripción de response.
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ Primero, importa `Path` de `fastapi`, e importa `Annotated`:
|
||||
|
||||
{* ../../docs_src/path_params_numeric_validations/tutorial001_an_py310.py hl[1,3] *}
|
||||
|
||||
/// note | Nota
|
||||
/// info | Información
|
||||
|
||||
FastAPI agregó soporte para `Annotated` (y comenzó a recomendar su uso) en la versión 0.95.0.
|
||||
|
||||
@@ -131,7 +131,7 @@ Y también puedes declarar validaciones numéricas:
|
||||
* `lt`: `l`ess `t`han
|
||||
* `le`: `l`ess than or `e`qual
|
||||
|
||||
/// note | Nota
|
||||
/// info | Información
|
||||
|
||||
`Query`, `Path` y otras clases que verás más adelante son subclases de una clase común `Param`.
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Puedes definir archivos que serán subidos por el cliente utilizando `File`.
|
||||
|
||||
/// note | Nota
|
||||
/// info | Información
|
||||
|
||||
Para recibir archivos subidos, primero instala [`python-multipart`](https://github.com/Kludex/python-multipart).
|
||||
|
||||
@@ -28,7 +28,7 @@ Crea parámetros de archivo de la misma manera que lo harías para `Body` o `For
|
||||
|
||||
{* ../../docs_src/request_files/tutorial001_an_py310.py hl[9] *}
|
||||
|
||||
/// note | Nota
|
||||
/// info | Información
|
||||
|
||||
`File` es una clase que hereda directamente de `Form`.
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Puedes definir archivos y campos de formulario al mismo tiempo usando `File` y `Form`.
|
||||
|
||||
/// note | Nota
|
||||
/// info | Información
|
||||
|
||||
Para recibir archivos subidos y/o form data, primero instala [`python-multipart`](https://github.com/Kludex/python-multipart).
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ Observa que `status_code` es un parámetro del método "decorador" (`get`, `post
|
||||
|
||||
El parámetro `status_code` recibe un número con el código de estado HTTP.
|
||||
|
||||
/// note | Nota
|
||||
/// info | Información
|
||||
|
||||
`status_code` también puede recibir un `IntEnum`, como por ejemplo el [`http.HTTPStatus`](https://docs.python.org/3/library/http.html#http.HTTPStatus) de Python.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Pruebas { #testing }
|
||||
# Testing { #testing }
|
||||
|
||||
Gracias a [Starlette](https://www.starlette.dev/testclient/), escribir pruebas para aplicaciones de **FastAPI** es fácil y agradable.
|
||||
|
||||
@@ -8,7 +8,7 @@ Con él, puedes usar [pytest](https://docs.pytest.org/) directamente con **FastA
|
||||
|
||||
## Usando `TestClient` { #using-testclient }
|
||||
|
||||
/// note | Nota
|
||||
/// info | Información
|
||||
|
||||
Para usar `TestClient`, primero instala [`httpx`](https://www.python-httpx.org).
|
||||
|
||||
@@ -142,7 +142,7 @@ Por ejemplo:
|
||||
|
||||
Para más información sobre cómo pasar datos al backend (usando `httpx` o el `TestClient`) revisa la [documentación de HTTPX](https://www.python-httpx.org).
|
||||
|
||||
/// note | Nota
|
||||
/// info | Información
|
||||
|
||||
Ten en cuenta que el `TestClient` recibe datos que pueden ser convertidos a JSON, no modelos de Pydantic.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user