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 | |
|---|---|---|---|
|
|
794cfd0cb6 |
@@ -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,7 +492,9 @@ 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 mit einem einzigen Befehl in die [FastAPI Cloud](https://fastapicloud.com) deployen. 🚀
|
||||
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.
|
||||
|
||||
<div class="termy">
|
||||
|
||||
@@ -508,8 +510,6 @@ 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] *}
|
||||
|
||||
/// note | Hinweis
|
||||
/// info | Info
|
||||
|
||||
`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: Annotated[Item, Body(embed=True)]
|
||||
item: 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.
|
||||
|
||||
/// note | Hinweis
|
||||
/// info | Info
|
||||
|
||||
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 `
|
||||
|
||||
///
|
||||
|
||||
/// note | Hinweis
|
||||
/// info | Info
|
||||
|
||||
Um Cookies zu deklarieren, müssen Sie `Cookie` verwenden, da die Parameter sonst als Query-Parameter interpretiert würden.
|
||||
|
||||
///
|
||||
|
||||
/// note | Hinweis
|
||||
/// info | Info
|
||||
|
||||
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] *}
|
||||
|
||||
/// note | Hinweis
|
||||
/// info | Info
|
||||
|
||||
Beachten Sie, dass sich `response_description` speziell auf die Response bezieht, während `description` sich generell auf die *Pfadoperation* bezieht.
|
||||
|
||||
///
|
||||
|
||||
/// tip | Tipp
|
||||
/// check | Testen
|
||||
|
||||
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] *}
|
||||
|
||||
/// note | Hinweis
|
||||
/// info | Info
|
||||
|
||||
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)
|
||||
|
||||
/// note | Hinweis
|
||||
/// info | Info
|
||||
|
||||
`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.
|
||||
|
||||
/// note | Hinweis
|
||||
/// info | Info
|
||||
|
||||
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] *}
|
||||
|
||||
/// note | Hinweis
|
||||
/// info | Info
|
||||
|
||||
`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.
|
||||
|
||||
/// note | Hinweis
|
||||
/// info | Info
|
||||
|
||||
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.
|
||||
|
||||
/// note | Hinweis
|
||||
/// info | Info
|
||||
|
||||
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 }
|
||||
|
||||
/// note | Hinweis
|
||||
/// info | Info
|
||||
|
||||
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).
|
||||
|
||||
/// note | Hinweis
|
||||
/// info | Info
|
||||
|
||||
Beachten Sie, dass der `TestClient` Daten empfängt, die nach JSON konvertiert werden können, keine Pydantic-Modelle.
|
||||
|
||||
|
||||
@@ -469,7 +469,7 @@ Experimente mudar a seguinte linha:
|
||||
... "item_price": item.price ...
|
||||
```
|
||||
|
||||
...e veja como seu editor irá auto-completar os atributos e saberá os tipos:
|
||||
...e veja como seu editor irá autocompletar os atributos e saberá os tipos:
|
||||
|
||||

|
||||
|
||||
@@ -492,9 +492,7 @@ Para um exemplo mais completo incluindo mais recursos, veja o <a href="https://f
|
||||
|
||||
### Implemente sua aplicação (opcional) { #deploy-your-app-optional }
|
||||
|
||||
Você pode opcionalmente implantar sua aplicação FastAPI na [FastAPI Cloud](https://fastapicloud.com), vá e entre na lista de espera se ainda não o fez. 🚀
|
||||
|
||||
Se você já tem uma conta na **FastAPI Cloud** (nós convidamos você da lista de espera 😉), pode implantar sua aplicação com um único comando.
|
||||
Você pode opcionalmente implantar sua aplicação FastAPI na [FastAPI Cloud](https://fastapicloud.com) com um único comando. 🚀
|
||||
|
||||
<div class="termy">
|
||||
|
||||
@@ -510,6 +508,8 @@ Deploying to FastAPI Cloud...
|
||||
|
||||
</div>
|
||||
|
||||
A CLI detectará automaticamente sua aplicação FastAPI e a implantará na nuvem. Se você não estiver autenticado, o navegador será aberto para concluir o processo de autenticação.
|
||||
|
||||
É isso! Agora você pode acessar sua aplicação nesse URL. ✨
|
||||
|
||||
#### Sobre a FastAPI Cloud { #about-fastapi-cloud }
|
||||
|
||||
@@ -108,7 +108,7 @@ Por exemplo:
|
||||
|
||||
{* ../../docs_src/body_multiple_params/tutorial004_an_py310.py hl[28] *}
|
||||
|
||||
/// info | Informação
|
||||
/// note | Nota
|
||||
|
||||
`Body` também possui todas as validações adicionais e metadados de parâmetros como em `Query`,`Path` e outras que você verá depois.
|
||||
|
||||
@@ -123,7 +123,7 @@ Por padrão, o **FastAPI** esperará que seu conteúdo venha no corpo diretament
|
||||
Mas se você quiser que ele espere por um JSON com uma chave `item` e dentro dele os conteúdos do modelo, como ocorre ao declarar vários parâmetros de corpo, você pode usar o parâmetro especial de `Body` chamado `embed`:
|
||||
|
||||
```Python
|
||||
item: Item = Body(embed=True)
|
||||
item: Annotated[Item, Body(embed=True)]
|
||||
```
|
||||
|
||||
como em:
|
||||
|
||||
@@ -8,7 +8,7 @@ Sua API quase sempre precisa enviar um corpo na **resposta**. Mas os clientes n
|
||||
|
||||
Para declarar um corpo da **requisição**, você utiliza os modelos do [Pydantic](https://docs.pydantic.dev/) com todos os seus poderes e benefícios.
|
||||
|
||||
/// info | Informação
|
||||
/// note | Nota
|
||||
|
||||
Para enviar dados, você deveria usar um dos: `POST` (o mais comum), `PUT`, `DELETE` ou `PATCH`.
|
||||
|
||||
|
||||
@@ -24,13 +24,13 @@ Mas lembre-se que quando você importa `Query`, `Path`, `Cookie` e outras de `fa
|
||||
|
||||
///
|
||||
|
||||
/// info | Informação
|
||||
/// note | Nota
|
||||
|
||||
Para declarar cookies, você precisa usar `Cookie`, pois caso contrário, os parâmetros seriam interpretados como parâmetros de consulta.
|
||||
|
||||
///
|
||||
|
||||
/// info | Informação
|
||||
/// note | Nota
|
||||
|
||||
Tenha em mente que, como os **navegadores lidam com cookies** de maneiras especiais e nos bastidores, eles **não** permitem facilmente que o **JavaScript** os acesse.
|
||||
|
||||
|
||||
@@ -72,13 +72,13 @@ Você pode especificar a descrição da resposta com o parâmetro `response_desc
|
||||
|
||||
{* ../../docs_src/path_operation_configuration/tutorial005_py310.py hl[18] *}
|
||||
|
||||
/// info | Informação
|
||||
/// note | Nota
|
||||
|
||||
Note que `response_description` se refere especificamente à resposta, a `description` se refere à *operação de rota* em geral.
|
||||
Observe que `response_description` se refere especificamente à resposta, a `description` se refere à *operação de rota* em geral.
|
||||
|
||||
///
|
||||
|
||||
/// check | Verifique
|
||||
/// tip | Dica
|
||||
|
||||
OpenAPI especifica que cada *operação de rota* requer uma descrição de resposta.
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ Primeiro, importe `Path` de `fastapi`, e importe `Annotated`:
|
||||
|
||||
{* ../../docs_src/path_params_numeric_validations/tutorial001_an_py310.py hl[1,3] *}
|
||||
|
||||
/// info | Informação
|
||||
/// note | Nota
|
||||
|
||||
O FastAPI adicionou suporte a `Annotated` (e passou a recomendá-lo) na versão 0.95.0.
|
||||
|
||||
@@ -131,7 +131,7 @@ E você também pode declarar validações numéricas:
|
||||
* `lt`: menor que (`l`ess `t`han)
|
||||
* `le`: menor que ou igual (`l`ess than or `e`qual)
|
||||
|
||||
/// info | Informação
|
||||
/// note | Nota
|
||||
|
||||
`Query`, `Path` e outras classes que você verá depois são subclasses de uma classe comum `Param`.
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Você pode definir arquivos para serem enviados pelo cliente usando `File`.
|
||||
|
||||
/// info | Informação
|
||||
/// note | Nota
|
||||
|
||||
Para receber arquivos enviados, primeiro instale [`python-multipart`](https://github.com/Kludex/python-multipart).
|
||||
|
||||
@@ -28,7 +28,7 @@ Crie parâmetros de arquivo da mesma forma que você faria para `Body` ou `Form`
|
||||
|
||||
{* ../../docs_src/request_files/tutorial001_an_py310.py hl[9] *}
|
||||
|
||||
/// info | Informação
|
||||
/// note | Nota
|
||||
|
||||
`File` é uma classe que herda diretamente de `Form`.
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Você pode definir arquivos e campos de formulário ao mesmo tempo usando `File` e `Form`.
|
||||
|
||||
/// info | Informação
|
||||
/// note | Nota
|
||||
|
||||
Para receber arquivos carregados e/ou dados de formulário, primeiro instale [`python-multipart`](https://github.com/Kludex/python-multipart).
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ Observe que `status_code` é um parâmetro do método "decorador" (`get`, `post`
|
||||
|
||||
O parâmetro `status_code` recebe um número com o código de status HTTP.
|
||||
|
||||
/// info | Informação
|
||||
/// note | Nota
|
||||
|
||||
`status_code` também pode receber um `IntEnum`, como [`http.HTTPStatus`](https://docs.python.org/3/library/http.html#http.HTTPStatus) do Python.
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ Com ele, você pode usar o [pytest](https://docs.pytest.org/) diretamente com **
|
||||
|
||||
## Usando `TestClient` { #using-testclient }
|
||||
|
||||
/// info | Informação
|
||||
/// note | Nota
|
||||
|
||||
Para usar o `TestClient`, primeiro instale [`httpx`](https://www.python-httpx.org).
|
||||
|
||||
@@ -142,7 +142,7 @@ Por exemplo:
|
||||
|
||||
Para mais informações sobre como passar dados para o backend (usando `httpx` ou `TestClient`), consulte a [documentação do HTTPX](https://www.python-httpx.org).
|
||||
|
||||
/// info | Informação
|
||||
/// note | Nota
|
||||
|
||||
Observe que o `TestClient` recebe dados que podem ser convertidos para JSON, não para modelos Pydantic.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user