Compare commits

...

148 Commits

Author SHA1 Message Date
Sebastián Ramírez
c519614b45 🔖 Release version 0.115.3 2024-10-22 15:26:52 +01:00
github-actions
9c794c9c0d 📝 Update release notes 2024-10-22 14:20:24 +00:00
Marcel Hellkamp
c4f8143dea ⬆️ Upgrade Starlette to >=0.40.0,<0.42.0 (#12469)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2024-10-22 15:19:56 +01:00
github-actions
45822d31f2 📝 Update release notes 2024-10-20 19:20:44 +00:00
Elton Jefferson
4c1a1938bc 📝 Fix broken link in docs (#12495) 2024-10-20 20:20:23 +01:00
github-actions
5afa6d7066 📝 Update release notes 2024-10-18 12:13:10 +00:00
github-actions
f0b5f8adf7 📝 Update release notes 2024-10-18 12:12:24 +00:00
YungYueh ChanLee
b0761c2552 🌐 Add Traditional Chinese translation for docs/zh-hant/docs/fastapi-cli.md (#12444) 2024-10-18 14:12:01 +02:00
YungYueh ChanLee
53d90074e5 🌐 Add Traditional Chinese translation for docs/zh-hant/docs/deployment/index.md (#12439) 2024-10-18 14:10:00 +02:00
github-actions
7038bedc5d 📝 Update release notes 2024-10-18 12:05:45 +00:00
Guilherme Rameh
48849f8a11 🌐 Add Portuguese translation for docs/pt/docs/how-to/testing-database.md (#12472) 2024-10-18 14:04:04 +02:00
github-actions
b7fb8eb656 📝 Update release notes 2024-10-18 12:03:01 +00:00
Luis Rodrigues
ac3c2dd965 🌐 Add Portuguese translation for docs/pt/docs/how-to/custom-docs-ui-assets.md (#12473) 2024-10-18 14:02:35 +02:00
github-actions
febf6b6a52 📝 Update release notes 2024-10-16 07:45:07 +00:00
leonardopaloschi
71f2be2387 🌐 Add Portuguese translation for docs/pt/docs/advanced/response-headers.md (#12458) 2024-10-16 09:44:45 +02:00
github-actions
50639525bf 📝 Update release notes 2024-10-15 12:34:11 +00:00
YungYueh ChanLee
80ba3fc5db 🌐 Add Traditional Chinese translation for docs/zh-hant/docs/deployment/cloud.md (#12440) 2024-10-15 14:33:07 +02:00
github-actions
d7942aea2d 📝 Update release notes 2024-10-15 12:32:58 +00:00
Rafael de Oliveira Marques
12c188b311 🌐 Update Portuguese translation for docs/pt/docs/python-types.md (#12428) 2024-10-15 14:32:27 +02:00
github-actions
9b09974cfc 📝 Update release notes 2024-10-15 11:39:19 +00:00
WISDERFIN
0507458504 🌐 Add Russian translation for docs/ru/docs/environment-variables.md (#12436) 2024-10-15 13:38:57 +02:00
github-actions
be03a7313e 📝 Update release notes 2024-10-15 10:39:19 +00:00
Alejandra
111ced53af 👷 Update issue manager workflow (#12457)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2024-10-15 12:38:53 +02:00
github-actions
d63f0d60ba 📝 Update release notes 2024-10-15 10:03:32 +00:00
YungYueh ChanLee
4d8d092925 🌐 Add Traditional Chinese translation for docs/zh-hant/docs/resources/index.md (#12443) 2024-10-15 12:00:33 +02:00
github-actions
33cd8bbcc5 📝 Update release notes 2024-10-15 09:58:11 +00:00
YungYueh ChanLee
73546a68e6 🌐 Add Traditional Chinese translation for docs/zh-hant/docs/about/index.md (#12438) 2024-10-15 11:57:21 +02:00
github-actions
c9f11c2b73 📝 Update release notes 2024-10-15 09:53:37 +00:00
Rafael de Oliveira Marques
e58c185526 🌐 Add Portuguese translation for docs/pt/docs/tutorial/query-param-models.md (#12414) 2024-10-15 11:53:14 +02:00
github-actions
923d44de35 📝 Update release notes 2024-10-14 14:57:54 +00:00
Rafael de Oliveira Marques
7148584ac4 🌐 Remove Portuguese translation for docs/pt/docs/deployment.md (#12427) 2024-10-14 16:57:32 +02:00
github-actions
38f65c033f 📝 Update release notes 2024-10-14 10:52:26 +00:00
Sebastián Ramírez
5f998ee55a 🔧 Update team, include YuriiMotov 🚀 (#12453) 2024-10-14 12:51:58 +02:00
github-actions
7358ed246e 📝 Update release notes 2024-10-14 09:17:01 +00:00
Anderson Rocha
d4e183da3f 🌐 Add Portuguese translation for docs/pt/docs/tutorial/body-updates.md (#12381) 2024-10-14 11:16:06 +02:00
github-actions
0e4dc88bd7 📝 Update release notes 2024-10-14 09:15:46 +00:00
Paulo Falcão
b887d434db 🌐 Add Portuguese translation for docs/pt/docs/advanced/response-cookies.md (#12417) 2024-10-14 11:15:24 +02:00
github-actions
766a14ddff 📝 Update release notes 2024-10-12 13:59:03 +00:00
Sebastián Ramírez
6384f730f7 👷 Refactor label-approved, make it an internal script instead of an external GitHub Action (#12280) 2024-10-12 13:58:30 +00:00
github-actions
84ef149f83 📝 Update release notes 2024-10-12 13:49:27 +00:00
Sebastián Ramírez
495d90161b 👷 Fix smokeshow, checkout files on CI (#12434) 2024-10-12 15:47:46 +02:00
github-actions
ac6c08c71f 📝 Update release notes 2024-10-12 12:28:10 +00:00
Sebastián Ramírez
a30eb6f517 👷 Use uv in CI (#12281) 2024-10-12 14:27:19 +02:00
github-actions
3347f0dde5 📝 Update release notes 2024-10-12 10:29:52 +00:00
dependabot[bot]
91672fb9ed ⬆ Update httpx requirement from <0.25.0,>=0.23.0 to >=0.23.0,<0.28.0 (#11509)
Updates the requirements on [httpx](https://github.com/encode/httpx) to permit the latest version.
- [Release notes](https://github.com/encode/httpx/releases)
- [Changelog](https://github.com/encode/httpx/blob/master/CHANGELOG.md)
- [Commits](https://github.com/encode/httpx/compare/0.23.0...0.27.0)

---
updated-dependencies:
- dependency-name: httpx
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-12 12:29:31 +02:00
Sebastián Ramírez
07684aea79 🔖 Release version 0.115.2 2024-10-12 12:00:47 +02:00
github-actions
63c428fbf9 📝 Update release notes 2024-10-12 09:59:23 +00:00
Sebastián Ramírez
b77f2351d1 ⬆️ Upgrade Starlette to >=0.37.2,<0.41.0 (#12431) 2024-10-12 11:59:01 +02:00
Sebastián Ramírez
113da5b0a7 🔖 Release version 0.115.1 2024-10-12 11:51:09 +02:00
github-actions
f0be768646 📝 Update release notes 2024-10-12 09:45:17 +00:00
Felix Fanghaenel
e049fc4ea1 🐛 Fix openapi generation with responses kwarg (#10895)
Co-authored-by: flxdot <felix.fanghaenel@nitrex.com>
Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
Co-authored-by: Sławek Ehlert <slawomir.ehlert@gmail.com>
2024-10-12 11:44:57 +02:00
github-actions
b29cf1621a 📝 Update release notes 2024-10-12 09:36:55 +00:00
José Pacheco
8ae4603d68 🐛 Remove Required shadowing from fastapi using Pydantic v2 (#12197)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
2024-10-12 11:36:32 +02:00
github-actions
529155e72e 📝 Update release notes 2024-10-09 20:12:15 +00:00
pre-commit-ci[bot]
104dc0b8d8 ⬆ [pre-commit.ci] pre-commit autoupdate (#12396)
updates:
- [github.com/pre-commit/pre-commit-hooks: v4.6.0 → v5.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.6.0...v5.0.0)
- [github.com/astral-sh/ruff-pre-commit: v0.6.8 → v0.6.9](https://github.com/astral-sh/ruff-pre-commit/compare/v0.6.8...v0.6.9)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-10-09 22:11:46 +02:00
github-actions
dbb4a91e12 📝 Update release notes 2024-10-09 19:45:08 +00:00
Sebastián Ramírez
7daaac2bc3 Add new tutorial for SQL databases with SQLModel (#12285) 2024-10-09 21:44:42 +02:00
github-actions
13a18f80b3 📝 Update release notes 2024-10-08 11:01:43 +00:00
Sebastián Ramírez
c6dfdb8523 🔨 Add script to generate variants of files (#12405) 2024-10-08 11:01:17 +00:00
github-actions
a94d61b2c0 📝 Update release notes 2024-10-08 10:55:50 +00:00
Sebastián Ramírez
40490abaa3 ♻️ Update type annotations for improved python-multipart (#12407) 2024-10-08 12:55:26 +02:00
github-actions
fcb15b4db1 📝 Update release notes 2024-10-08 08:38:00 +00:00
Sebastián Ramírez
018e303fd9 🔧 Add speakeasy-api to sponsors_badge.yml (#12404) 2024-10-08 08:37:32 +00:00
github-actions
6345147c24 📝 Update release notes 2024-10-07 20:25:03 +00:00
Sebastián Ramírez
95f167f048 Add docs dependency: markdown-include-variants (#12399) 2024-10-07 20:24:40 +00:00
github-actions
ecc4133907 📝 Update release notes 2024-10-07 20:18:29 +00:00
Sebastián Ramírez
797cad7162 📝 Fix extra mdx-base-path paths (#12397) 2024-10-07 20:18:07 +00:00
github-actions
e45b5d3589 📝 Update release notes 2024-10-07 20:11:42 +00:00
Sebastián Ramírez
b45192c68a 👷 Tweak labeler to not override custom labels (#12398) 2024-10-07 20:11:20 +00:00
github-actions
31aec0967a 📝 Update release notes 2024-10-07 11:32:19 +00:00
Balthazar Rouberol
e9c6408af7 📝 Add External Link: How to profile a FastAPI asynchronous request (#12389) 2024-10-07 11:31:55 +00:00
github-actions
3f8a527b50 📝 Update release notes 2024-10-07 11:23:42 +00:00
Rafael de Oliveira Marques
e62960e323 🌐 Add Portuguese translation for docs/pt/docs/tutorial/cookie-param-models.md (#12298) 2024-10-07 13:23:18 +02:00
github-actions
b36b7dfed0 📝 Update release notes 2024-10-06 20:37:15 +00:00
Sebastián Ramírez
0f7d67e85c 🔧 Remove base_path for mdx_include Markdown extension in MkDocs (#12391) 2024-10-06 22:36:54 +02:00
github-actions
c67b41546c 📝 Update release notes 2024-10-06 20:14:33 +00:00
Sebastián Ramírez
1705a8c37f 👷 Update deploy-docs-notify URL (#12392) 2024-10-06 20:14:05 +00:00
github-actions
ad8b3ba3ec 📝 Update release notes 2024-10-05 12:49:28 +00:00
Sebastián Ramírez
9d6ec4aa77 👷 Update Cloudflare GitHub Action (#12387) 2024-10-05 14:49:04 +02:00
github-actions
ea1265b78b 📝 Update release notes 2024-10-04 11:58:03 +00:00
dependabot[bot]
caa298aefe ⬆ Bump pypa/gh-action-pypi-publish from 1.10.1 to 1.10.3 (#12386)
Bumps [pypa/gh-action-pypi-publish](https://github.com/pypa/gh-action-pypi-publish) from 1.10.1 to 1.10.3.
- [Release notes](https://github.com/pypa/gh-action-pypi-publish/releases)
- [Commits](https://github.com/pypa/gh-action-pypi-publish/compare/v1.10.1...v1.10.3)

---
updated-dependencies:
- dependency-name: pypa/gh-action-pypi-publish
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-04 13:57:23 +02:00
github-actions
82b95dcef8 📝 Update release notes 2024-10-04 11:56:57 +00:00
dependabot[bot]
757eaacd59 ⬆ Bump mkdocstrings[python] from 0.25.1 to 0.26.1 (#12371)
Bumps [mkdocstrings[python]](https://github.com/mkdocstrings/mkdocstrings) from 0.25.1 to 0.26.1.
- [Release notes](https://github.com/mkdocstrings/mkdocstrings/releases)
- [Changelog](https://github.com/mkdocstrings/mkdocstrings/blob/main/CHANGELOG.md)
- [Commits](https://github.com/mkdocstrings/mkdocstrings/compare/0.25.1...0.26.1)

---
updated-dependencies:
- dependency-name: mkdocstrings[python]
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Alejandra <90076947+alejsdev@users.noreply.github.com>
2024-10-04 13:56:35 +02:00
github-actions
deec2e591e 📝 Update release notes 2024-10-04 11:39:01 +00:00
dependabot[bot]
8953d9a323 ⬆ Bump griffe-typingdoc from 0.2.6 to 0.2.7 (#12370)
Bumps [griffe-typingdoc](https://github.com/mkdocstrings/griffe-typingdoc) from 0.2.6 to 0.2.7.
- [Release notes](https://github.com/mkdocstrings/griffe-typingdoc/releases)
- [Changelog](https://github.com/mkdocstrings/griffe-typingdoc/blob/main/CHANGELOG.md)
- [Commits](https://github.com/mkdocstrings/griffe-typingdoc/compare/0.2.6...0.2.7)

---
updated-dependencies:
- dependency-name: griffe-typingdoc
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-04 13:37:26 +02:00
github-actions
d12db0b26c 📝 Update release notes 2024-10-04 11:36:26 +00:00
Pavlo Pohorieltsev
3f3a3dd664 📝 Update link to Swagger UI configuration docs (#12264) 2024-10-04 13:34:57 +02:00
github-actions
f2fb0251cc 📝 Update release notes 2024-10-04 11:26:21 +00:00
pre-commit-ci[bot]
a096615f79 ⬆ [pre-commit.ci] pre-commit autoupdate (#12331)
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.6.7 → v0.6.8](https://github.com/astral-sh/ruff-pre-commit/compare/v0.6.7...v0.6.8)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-10-04 13:21:41 +02:00
github-actions
3d24833272 📝 Update release notes 2024-10-04 11:20:57 +00:00
github-actions
c08b80d09f 📝 Update release notes 2024-10-04 11:20:35 +00:00
Kayque Govetri
c93810e097 📝 Adding links for Playwright and Vite in docs/project-generation.md (#12274) 2024-10-04 13:16:34 +02:00
AnandaCampelo
a681aeba6d 🌐 Add Portuguese translation for docs/pt/docs/how-to/graphql.md (#12215) 2024-10-04 13:15:21 +02:00
github-actions
e2217e24b9 📝 Update release notes 2024-10-04 11:14:33 +00:00
Rafael de Oliveira Marques
0e7806e3f9 🌐 Add Portuguese translation for docs/pt/docs/advanced/security/oauth2-scopes.md (#12263) 2024-10-04 13:11:41 +02:00
github-actions
5820d4261e 📝 Update release notes 2024-10-04 11:10:09 +00:00
github-actions
304f514ed9 📝 Update release notes 2024-10-04 11:08:00 +00:00
marcelomarkus
17e234452a 🌐 Add Portuguese translation for docs/pt/docs/deployment/concepts.md (#12219) 2024-10-04 13:04:50 +02:00
marcelomarkus
fa50b0c73c 🌐 Add Portuguese translation for docs/pt/docs/how-to/conditional-openapi.md (#12221) 2024-10-04 13:03:46 +02:00
github-actions
b1c03ba57e 📝 Update release notes 2024-10-04 11:03:27 +00:00
github-actions
98d190f780 📝 Update release notes 2024-10-04 11:01:25 +00:00
João Pedro Pereira Holanda
69921b463e 🌐 Add Portuguese translation for docs/pt/docs/advanced/response-directly.md (#12266) 2024-10-04 13:00:29 +02:00
github-actions
ed477ee887 📝 Update release notes 2024-10-04 10:58:40 +00:00
Rafael de Oliveira Marques
ca68c99a6e 🌐 Update Portuguese translation for docs/pt/docs/tutorial/cookie-params.md (#12297) 2024-10-04 12:58:03 +02:00
kkotipy
0030f1749e 🌐 Fix Korean translation for docs/ko/docs/tutorial/index.md (#12278) 2024-10-04 10:57:17 +00:00
github-actions
919721ce8d 📝 Update release notes 2024-10-04 10:56:12 +00:00
Anderson Rocha
f0ebae6e9e 🌐 Update Portuguese translation for docs/pt/docs/advanced/security/http-basic-auth.md (#12275) 2024-10-04 12:55:49 +02:00
github-actions
847296e885 📝 Update release notes 2024-09-26 17:17:48 +00:00
Sebastián Ramírez
bb018fc46c 🔧 Update sponsors, remove Fine.dev (#12271) 2024-09-26 17:17:21 +00:00
github-actions
10f3cb5ab1 📝 Update release notes 2024-09-24 10:14:28 +00:00
pre-commit-ci[bot]
d9e989e274 ⬆ [pre-commit.ci] pre-commit autoupdate (#12253)
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.6.5 → v0.6.7](https://github.com/astral-sh/ruff-pre-commit/compare/v0.6.5...v0.6.7)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-09-24 12:14:00 +02:00
github-actions
9606b916ef 📝 Update release notes 2024-09-21 21:38:11 +00:00
marcelomarkus
6a2ad7031c 🌐 Add Portuguese translation for docs/pt/docs/deployment/cloud.md (#12217) 2024-09-21 23:37:48 +02:00
github-actions
f6dfb832c5 📝 Update release notes 2024-09-20 11:34:29 +00:00
Javier Sánchez Castro
2cdf111e61 ✏️ Fix typo in docs/es/docs/python-types.md (#12235) 2024-09-20 11:34:07 +00:00
github-actions
13e20228a9 📝 Update release notes 2024-09-20 11:15:35 +00:00
Max Scheijen
6aefc31600 🌐 Add Dutch translation for docs/nl/docs/environment-variables.md (#12200) 2024-09-20 13:13:32 +02:00
github-actions
2459a009f4 📝 Update release notes 2024-09-20 11:11:21 +00:00
João Gustavo Rogel de Oliveira
b1024e73be 🌐 Add Portuguese translation for docs/pt/docs/deployment/manually.md (#12210) 2024-09-20 13:10:02 +02:00
github-actions
4e3db0b689 📝 Update release notes 2024-09-20 11:03:12 +00:00
marcelomarkus
0b1da2d910 🌐 Add Portuguese translation for docs/pt/docs/deployment/server-workers.md (#12220) 2024-09-20 13:01:03 +02:00
github-actions
cf93157be7 📝 Update release notes 2024-09-20 11:00:31 +00:00
marcelomarkus
97ac2286aa 🌐 Add Portuguese translation for docs/pt/docs/how-to/configure-swagger-ui.md (#12222) 2024-09-20 13:00:08 +02:00
github-actions
7c6f2f8fde 📝 Update release notes 2024-09-19 09:47:54 +00:00
Albert Villanova del Moral
6cc24416e2 ✏️ Fix docstring typos in http security (#12223)
Fix docstring typos in http security
2024-09-19 11:47:28 +02:00
github-actions
4d6cab3ec6 📝 Update release notes 2024-09-18 16:10:21 +00:00
Sofie Van Landeghem
42e0e368bc 📝 Fix small typos in the documentation (#12213) 2024-09-18 18:09:57 +02:00
Sebastián Ramírez
40e33e492d 🔖 Release version 0.115.0 2024-09-17 21:07:35 +02:00
Sebastián Ramírez
b36047b54a 📝 Update release notes 2024-09-17 21:06:26 +02:00
github-actions
7eadeb69bd 📝 Update release notes 2024-09-17 18:54:35 +00:00
Sebastián Ramírez
55035f440b Add support for Pydantic models for parameters using Query, Cookie, Header (#12199) 2024-09-17 20:54:10 +02:00
github-actions
0903da78c9 📝 Update release notes 2024-09-16 22:00:35 +00:00
pre-commit-ci[bot]
4b2b14a8e8 ⬆ [pre-commit.ci] pre-commit autoupdate (#12204)
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.6.4 → v0.6.5](https://github.com/astral-sh/ruff-pre-commit/compare/v0.6.4...v0.6.5)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-09-17 00:00:09 +02:00
github-actions
35df20c79c 📝 Update release notes 2024-09-15 19:04:38 +00:00
Rafael de Oliveira Marques
8eb3c5621f 🌐 Add Portuguese translation for docs/pt/docs/advanced/security/http-basic-auth.md (#12195) 2024-09-15 21:04:17 +02:00
Sebastián Ramírez
2ada1615a3 🔖 Release version 0.114.2 2024-09-13 22:46:33 +02:00
github-actions
3a5fd71f55 📝 Update release notes 2024-09-13 09:51:26 +00:00
Nico Tonnhofer
88d4f2cb18 🐛 Fix form field regression (#12194) 2024-09-13 11:51:00 +02:00
github-actions
0fc6e34135 📝 Update release notes 2024-09-13 09:15:10 +00:00
Sebastián Ramírez
2a4351105e 💡 Add comments with instructions for Playwright screenshot scripts (#12193) 2024-09-13 11:14:46 +02:00
github-actions
ed66d70513 📝 Update release notes 2024-09-12 17:06:34 +00:00
Rafael de Oliveira Marques
e50facaf22 🌐 Add Portuguese translation for docs/pt/docs/tutorial/request-form-models.md (#12175) 2024-09-12 19:03:48 +02:00
github-actions
93e50e373b 📝 Update release notes 2024-09-12 17:03:26 +00:00
Waket Zheng
4a94fe3c82 🌐 Add Chinese translation for docs/zh/docs/project-generation.md (#12170) 2024-09-12 19:01:54 +02:00
github-actions
492943fdb1 📝 Update release notes 2024-09-12 17:01:01 +00:00
Max Scheijen
c8e644d19e 🌐 Add Dutch translation for docs/nl/docs/python-types.md (#12158) 2024-09-12 19:00:36 +02:00
github-actions
ba0bb6212e 📝 Update release notes 2024-09-11 22:50:18 +00:00
Sebastián Ramírez
24b8f2668b Add inline-snapshot for tests (#12189) 2024-09-11 22:49:55 +00:00
749 changed files with 15363 additions and 11721 deletions

View File

@@ -7,6 +7,10 @@ on:
types:
- opened
- synchronize
env:
UV_SYSTEM_PYTHON: 1
jobs:
changes:
runs-on: ubuntu-latest
@@ -48,18 +52,20 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.11"
- uses: actions/cache@v4
id: cache
- name: Setup uv
uses: astral-sh/setup-uv@v3
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-python-docs-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml', 'requirements-docs.txt', 'requirements-docs-insiders.txt', 'requirements-docs-tests.txt') }}-v08
version: "0.4.15"
enable-cache: true
cache-dependency-glob: |
requirements**.txt
pyproject.toml
- name: Install docs extras
if: steps.cache.outputs.cache-hit != 'true'
run: pip install -r requirements-docs.txt
run: uv pip install -r requirements-docs.txt
# Install MkDocs Material Insiders here just to put it in the cache for the rest of the steps
- name: Install Material for MkDocs Insiders
if: ( github.event_name != 'pull_request' || github.secret_source == 'Actions' ) && steps.cache.outputs.cache-hit != 'true'
run: pip install -r requirements-docs-insiders.txt
if: ( github.event_name != 'pull_request' || github.secret_source == 'Actions' )
run: uv pip install -r requirements-docs-insiders.txt
env:
TOKEN: ${{ secrets.FASTAPI_MKDOCS_MATERIAL_INSIDERS }}
- name: Verify Docs
@@ -88,17 +94,19 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.11"
- uses: actions/cache@v4
id: cache
- name: Setup uv
uses: astral-sh/setup-uv@v3
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-python-docs-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml', 'requirements-docs.txt', 'requirements-docs-insiders.txt', 'requirements-docs-tests.txt') }}-v08
version: "0.4.15"
enable-cache: true
cache-dependency-glob: |
requirements**.txt
pyproject.toml
- name: Install docs extras
if: steps.cache.outputs.cache-hit != 'true'
run: pip install -r requirements-docs.txt
run: uv pip install -r requirements-docs.txt
- name: Install Material for MkDocs Insiders
if: ( github.event_name != 'pull_request' || github.secret_source == 'Actions' ) && steps.cache.outputs.cache-hit != 'true'
run: pip install -r requirements-docs-insiders.txt
if: ( github.event_name != 'pull_request' || github.secret_source == 'Actions' )
run: uv pip install -r requirements-docs-insiders.txt
env:
TOKEN: ${{ secrets.FASTAPI_MKDOCS_MATERIAL_INSIDERS }}
- name: Update Languages

View File

@@ -12,6 +12,9 @@ permissions:
pull-requests: write
statuses: write
env:
UV_SYSTEM_PYTHON: 1
jobs:
deploy-docs:
runs-on: ubuntu-latest
@@ -25,21 +28,22 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.11"
- uses: actions/cache@v4
id: cache
- name: Setup uv
uses: astral-sh/setup-uv@v3
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-python-github-actions-${{ env.pythonLocation }}-${{ hashFiles('requirements-github-actions.txt') }}-v01
version: "0.4.15"
enable-cache: true
cache-dependency-glob: |
requirements**.txt
pyproject.toml
- name: Install GitHub Actions dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: pip install -r requirements-github-actions.txt
run: uv pip install -r requirements-github-actions.txt
- name: Deploy Docs Status Pending
run: python ./scripts/deploy_docs_status.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_SHA: ${{ github.event.workflow_run.head_sha }}
RUN_ID: ${{ github.run_id }}
- name: Clean site
run: |
rm -rf ./site
@@ -55,19 +59,19 @@ jobs:
# hashFiles returns an empty string if there are no files
if: hashFiles('./site/*')
id: deploy
uses: cloudflare/pages-action@v1
env:
PROJECT_NAME: fastapitiangolo
BRANCH: ${{ ( github.event.workflow_run.head_repository.full_name == github.repository && github.event.workflow_run.head_branch == 'master' && 'main' ) || ( github.event.workflow_run.head_sha ) }}
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: fastapitiangolo
directory: './site'
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ ( github.event.workflow_run.head_repository.full_name == github.repository && github.event.workflow_run.head_branch == 'master' && 'main' ) || ( github.event.workflow_run.head_sha ) }}
command: pages deploy ./site --project-name=${{ env.PROJECT_NAME }} --branch=${{ env.BRANCH }}
- name: Comment Deploy
run: python ./scripts/deploy_docs_status.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEPLOY_URL: ${{ steps.deploy.outputs.url }}
DEPLOY_URL: ${{ steps.deploy.outputs.deployment-url }}
COMMIT_SHA: ${{ github.event.workflow_run.head_sha }}
RUN_ID: ${{ github.run_id }}
IS_DONE: "true"

View File

@@ -39,5 +39,9 @@ jobs:
"waiting": {
"delay": 2628000,
"message": "As this PR has been waiting for the original user for a while but seems to be inactive, it's now going to be closed. But if there's anyone interested, feel free to create a new PR."
},
"invalid": {
"delay": 0,
"message": "This was marked as invalid and will be closed now. If this is an error, please provide additional details."
}
}

View File

@@ -8,6 +8,9 @@ on:
permissions:
pull-requests: write
env:
UV_SYSTEM_PYTHON: 1
jobs:
label-approved:
if: github.repository_owner == 'fastapi'
@@ -17,10 +20,26 @@ jobs:
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- uses: docker://tiangolo/label-approved:0.0.4
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
config: >
python-version: "3.11"
- name: Setup uv
uses: astral-sh/setup-uv@v3
with:
version: "0.4.15"
enable-cache: true
cache-dependency-glob: |
requirements**.txt
pyproject.toml
- name: Install GitHub Actions dependencies
run: uv pip install -r requirements-github-actions.txt
- name: Label Approved
run: python ./scripts/label_approved.py
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
CONFIG: >
{
"approved-1":
{

View File

@@ -17,6 +17,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v5
if: ${{ github.event.action != 'labeled' && github.event.action != 'unlabeled' }}
- run: echo "Done adding labels"
# Run this after labeler applied labels
check-labels:
needs:

View File

@@ -18,6 +18,9 @@ on:
permissions:
discussions: write
env:
UV_SYSTEM_PYTHON: 1
jobs:
notify-translations:
runs-on: ubuntu-latest
@@ -27,6 +30,19 @@ jobs:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- uses: actions/checkout@v4
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Setup uv
uses: astral-sh/setup-uv@v3
with:
version: "0.4.15"
enable-cache: true
cache-dependency-glob: |
requirements**.txt
pyproject.toml
# Allow debugging with tmate
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3

View File

@@ -35,7 +35,7 @@ jobs:
TIANGOLO_BUILD_PACKAGE: ${{ matrix.package }}
run: python -m build
- name: Publish
uses: pypa/gh-action-pypi-publish@v1.10.1
uses: pypa/gh-action-pypi-publish@v1.10.3
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}

View File

@@ -8,6 +8,9 @@ on:
permissions:
statuses: write
env:
UV_SYSTEM_PYTHON: 1
jobs:
smokeshow:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
@@ -18,19 +21,25 @@ jobs:
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
- run: pip install smokeshow
- name: Setup uv
uses: astral-sh/setup-uv@v3
with:
version: "0.4.15"
enable-cache: true
cache-dependency-glob: |
requirements**.txt
pyproject.toml
- run: uv pip install -r requirements-github-actions.txt
- uses: actions/download-artifact@v4
with:
name: coverage-html
path: htmlcov
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- run: smokeshow upload htmlcov
env:
SMOKESHOW_GITHUB_STATUS_DESCRIPTION: Coverage {coverage-percentage}

View File

@@ -12,6 +12,9 @@ on:
# cron every week on monday
- cron: "0 0 * * 1"
env:
UV_SYSTEM_PYTHON: 1
jobs:
lint:
runs-on: ubuntu-latest
@@ -25,19 +28,18 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.11"
# Issue ref: https://github.com/actions/setup-python/issues/436
# cache: "pip"
# cache-dependency-path: pyproject.toml
- uses: actions/cache@v4
id: cache
- name: Setup uv
uses: astral-sh/setup-uv@v3
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-pydantic-v2-${{ hashFiles('pyproject.toml', 'requirements-tests.txt', 'requirements-docs-tests.txt') }}-test-v08
version: "0.4.15"
enable-cache: true
cache-dependency-glob: |
requirements**.txt
pyproject.toml
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: pip install -r requirements-tests.txt
run: uv pip install -r requirements-tests.txt
- name: Install Pydantic v2
run: pip install --upgrade "pydantic>=2.0.2,<3.0.0"
run: uv pip install --upgrade "pydantic>=2.0.2,<3.0.0"
- name: Lint
run: bash scripts/lint.sh
@@ -63,23 +65,22 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# Issue ref: https://github.com/actions/setup-python/issues/436
# cache: "pip"
# cache-dependency-path: pyproject.toml
- uses: actions/cache@v4
id: cache
- name: Setup uv
uses: astral-sh/setup-uv@v3
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ matrix.pydantic-version }}-${{ hashFiles('pyproject.toml', 'requirements-tests.txt', 'requirements-docs-tests.txt') }}-test-v08
version: "0.4.15"
enable-cache: true
cache-dependency-glob: |
requirements**.txt
pyproject.toml
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: pip install -r requirements-tests.txt
run: uv pip install -r requirements-tests.txt
- name: Install Pydantic v1
if: matrix.pydantic-version == 'pydantic-v1'
run: pip install "pydantic>=1.10.0,<2.0.0"
run: uv pip install "pydantic>=1.10.0,<2.0.0"
- name: Install Pydantic v2
if: matrix.pydantic-version == 'pydantic-v2'
run: pip install --upgrade "pydantic>=2.0.2,<3.0.0"
run: uv pip install --upgrade "pydantic>=2.0.2,<3.0.0"
- run: mkdir coverage
- name: Test
run: bash scripts/test.sh
@@ -105,16 +106,22 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: '3.8'
# Issue ref: https://github.com/actions/setup-python/issues/436
# cache: "pip"
# cache-dependency-path: pyproject.toml
- name: Setup uv
uses: astral-sh/setup-uv@v3
with:
version: "0.4.15"
enable-cache: true
cache-dependency-glob: |
requirements**.txt
pyproject.toml
- name: Install Dependencies
run: uv pip install -r requirements-tests.txt
- name: Get coverage files
uses: actions/download-artifact@v4
with:
pattern: coverage-*
path: coverage
merge-multiple: true
- run: pip install coverage[toml]
- run: ls -la coverage
- run: coverage combine coverage
- run: coverage report

View File

@@ -4,7 +4,7 @@ default_language_version:
python: python3.10
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-toml
@@ -14,7 +14,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.4
rev: v0.6.9
hooks:
- id: ruff
args:

View File

@@ -55,7 +55,6 @@ The key features are:
<a href="https://www.withcoherence.com/?utm_medium=advertising&utm_source=fastapi&utm_campaign=website" target="_blank" title="Coherence"><img src="https://fastapi.tiangolo.com/img/sponsors/coherence.png"></a>
<a href="https://www.mongodb.com/developer/languages/python/python-quickstart-fastapi/?utm_campaign=fastapi_framework&utm_source=fastapi_sponsorship&utm_medium=web_referral" target="_blank" title="Simplify Full Stack Development with FastAPI & MongoDB"><img src="https://fastapi.tiangolo.com/img/sponsors/mongodb.png"></a>
<a href="https://zuplo.link/fastapi-gh" target="_blank" title="Zuplo: Scale, Protect, Document, and Monetize your FastAPI"><img src="https://fastapi.tiangolo.com/img/sponsors/zuplo.png"></a>
<a href="https://fine.dev?ref=fastapibadge" target="_blank" title="Fine's AI FastAPI Workflow: Effortlessly Deploy and Integrate FastAPI into Your Project"><img src="https://fastapi.tiangolo.com/img/sponsors/fine.png"></a>
<a href="https://liblab.com?utm_source=fastapi" target="_blank" title="liblab - Generate SDKs from FastAPI"><img src="https://fastapi.tiangolo.com/img/sponsors/liblab.png"></a>
<a href="https://github.com/deepset-ai/haystack/" target="_blank" title="Build powerful search from composable, open source building blocks"><img src="https://fastapi.tiangolo.com/img/sponsors/haystack-fastapi.svg"></a>
<a href="https://databento.com/" target="_blank" title="Pay as you go for market data"><img src="https://fastapi.tiangolo.com/img/sponsors/databento.svg"></a>
@@ -96,7 +95,7 @@ The key features are:
"_Honestly, what you've built looks super solid and polished. In many ways, it's what I wanted **Hug** to be - it's really inspiring to see someone build that._"
<div style="text-align: right; margin-right: 10%;">Timothy Crosley - <strong><a href="https://www.hug.rest/" target="_blank">Hug</a> creator</strong> <a href="https://news.ycombinator.com/item?id=19455465" target="_blank"><small>(ref)</small></a></div>
<div style="text-align: right; margin-right: 10%;">Timothy Crosley - <strong><a href="https://github.com/hugapi/hug" target="_blank">Hug</a> creator</strong> <a href="https://news.ycombinator.com/item?id=19455465" target="_blank"><small>(ref)</small></a></div>
---

View File

@@ -87,7 +87,7 @@ FastAPI Python ilə API yaratmaq üçün standart Python <abbr title="Tip Məsl
"_Düzünü desəm, sizin qurduğunuz şey həqiqətən möhkəm və peşəkar görünür. Bir çox cəhətdən **Hug**-un olmasını istədiyim kimdir - kiminsə belə bir şey qurduğunu görmək həqiqətən ruhlandırıcıdır._"
<div style="text-align: right; margin-right: 10%;">Timothy Crosley - <strong><a href="https://www.hug.rest/" target="_blank">Hug</a> creator</strong> <a href="https://news.ycombinator.com/item?id=19455465" target="_blank"><small>(ref)</small></a></div>
<div style="text-align: right; margin-right: 10%;">Timothy Crosley - <strong><a href="https://github.com/hugapi/hug" target="_blank">Hug</a> creator</strong> <a href="https://news.ycombinator.com/item?id=19455465" target="_blank"><small>(ref)</small></a></div>
---

View File

@@ -85,7 +85,7 @@ FastAPI একটি আধুনিক, দ্রুত ( বেশি ক্
"\_সত্যিই, আপনি যা তৈরি করেছেন তা খুব মজবুত এবং পরিপূর্ন৷ অনেক উপায়ে, আমি যা **Hug** এ করতে চেয়েছিলাম - তা কাউকে তৈরি করতে দেখে আমি সত্যিই অনুপ্রানিত৷\_"
<div style="text-align: right; margin-right: 10%;">টিমোথি ক্রসলে - <strong><a href="https://www.hug.rest/" target="_blank">Hug</a> স্রষ্টা</strong> <a href="https://news.ycombinator.com/item?id=19455465" target="_blank"><small>(ref)</small></a></div>
<div style="text-align: right; margin-right: 10%;">টিমোথি ক্রসলে - <strong><a href="https://github.com/hugapi/hug" target="_blank">Hug</a> স্রষ্টা</strong> <a href="https://news.ycombinator.com/item?id=19455465" target="_blank"><small>(ref)</small></a></div>
---

View File

@@ -23,7 +23,7 @@ Python-এ ঐচ্ছিক "টাইপ হিন্ট" (যা "টাই
চলুন একটি সাধারণ উদাহরণ দিয়ে শুরু করি:
```Python
{!../../../docs_src/python_types/tutorial001.py!}
{!../../docs_src/python_types/tutorial001.py!}
```
এই প্রোগ্রামটি কল করলে আউটপুট হয়:
@@ -39,7 +39,7 @@ John Doe
* তাদেরকে মাঝখানে একটি স্পেস দিয়ে <abbr title="একটার পরে একটা একত্রিত করা">concatenate</abbr> করে।
```Python hl_lines="2"
{!../../../docs_src/python_types/tutorial001.py!}
{!../../docs_src/python_types/tutorial001.py!}
```
### এটি সম্পাদনা করুন
@@ -83,7 +83,7 @@ John Doe
এগুলিই "টাইপ হিন্ট":
```Python hl_lines="1"
{!../../../docs_src/python_types/tutorial002.py!}
{!../../docs_src/python_types/tutorial002.py!}
```
এটি ডিফল্ট ভ্যালু ঘোষণা করার মত নয় যেমন:
@@ -113,7 +113,7 @@ John Doe
এই ফাংশনটি দেখুন, এটিতে ইতিমধ্যে টাইপ হিন্ট রয়েছে:
```Python hl_lines="1"
{!../../../docs_src/python_types/tutorial003.py!}
{!../../docs_src/python_types/tutorial003.py!}
```
এডিটর ভেরিয়েবলগুলির টাইপ জানার কারণে, আপনি শুধুমাত্র অটোকমপ্লিশনই পান না, আপনি এরর চেকও পান:
@@ -123,7 +123,7 @@ John Doe
এখন আপনি জানেন যে আপনাকে এটি ঠিক করতে হবে, `age`-কে একটি স্ট্রিং হিসেবে রূপান্তর করতে `str(age)` ব্যবহার করতে হবে:
```Python hl_lines="2"
{!../../../docs_src/python_types/tutorial004.py!}
{!../../docs_src/python_types/tutorial004.py!}
```
## টাইপ ঘোষণা
@@ -144,7 +144,7 @@ John Doe
* `bytes`
```Python hl_lines="1"
{!../../../docs_src/python_types/tutorial005.py!}
{!../../docs_src/python_types/tutorial005.py!}
```
### টাইপ প্যারামিটার সহ জেনেরিক টাইপ
@@ -182,7 +182,7 @@ Python যত এগিয়ে যাচ্ছে, **নতুন সংস্
যেহেতু লিস্ট এমন একটি টাইপ যা অভ্যন্তরীণ টাইপগুলি ধারণ করে, আপনি তাদের স্কোয়ার ব্রাকেটের ভিতরে ব্যবহার করুন:
```Python hl_lines="1"
{!> ../../../docs_src/python_types/tutorial006_py39.py!}
{!> ../../docs_src/python_types/tutorial006_py39.py!}
```
////
@@ -192,7 +192,7 @@ Python যত এগিয়ে যাচ্ছে, **নতুন সংস্
`typing` থেকে `List` (বড় হাতের `L` দিয়ে) ইমপোর্ট করুন:
``` Python hl_lines="1"
{!> ../../../docs_src/python_types/tutorial006.py!}
{!> ../../docs_src/python_types/tutorial006.py!}
```
ভেরিয়েবলটি ঘোষণা করুন, একই কোলন (`:`) সিনট্যাক্স ব্যবহার করে।
@@ -202,7 +202,7 @@ Python যত এগিয়ে যাচ্ছে, **নতুন সংস্
যেহেতু লিস্ট এমন একটি টাইপ যা অভ্যন্তরীণ টাইপগুলি ধারণ করে, আপনি তাদের স্কোয়ার ব্রাকেটের ভিতরে করুন:
```Python hl_lines="4"
{!> ../../../docs_src/python_types/tutorial006.py!}
{!> ../../docs_src/python_types/tutorial006.py!}
```
////
@@ -240,7 +240,7 @@ Python যত এগিয়ে যাচ্ছে, **নতুন সংস্
//// tab | Python 3.9+
```Python hl_lines="1"
{!> ../../../docs_src/python_types/tutorial007_py39.py!}
{!> ../../docs_src/python_types/tutorial007_py39.py!}
```
////
@@ -248,7 +248,7 @@ Python যত এগিয়ে যাচ্ছে, **নতুন সংস্
//// tab | Python 3.8+
```Python hl_lines="1 4"
{!> ../../../docs_src/python_types/tutorial007.py!}
{!> ../../docs_src/python_types/tutorial007.py!}
```
////
@@ -269,7 +269,7 @@ Python যত এগিয়ে যাচ্ছে, **নতুন সংস্
//// tab | Python 3.9+
```Python hl_lines="1"
{!> ../../../docs_src/python_types/tutorial008_py39.py!}
{!> ../../docs_src/python_types/tutorial008_py39.py!}
```
////
@@ -277,7 +277,7 @@ Python যত এগিয়ে যাচ্ছে, **নতুন সংস্
//// tab | Python 3.8+
```Python hl_lines="1 4"
{!> ../../../docs_src/python_types/tutorial008.py!}
{!> ../../docs_src/python_types/tutorial008.py!}
```
////
@@ -299,7 +299,7 @@ Python 3.10-এ একটি **নতুন সিনট্যাক্স** আ
//// tab | Python 3.10+
```Python hl_lines="1"
{!> ../../../docs_src/python_types/tutorial008b_py310.py!}
{!> ../../docs_src/python_types/tutorial008b_py310.py!}
```
////
@@ -307,7 +307,7 @@ Python 3.10-এ একটি **নতুন সিনট্যাক্স** আ
//// tab | Python 3.8+
```Python hl_lines="1 4"
{!> ../../../docs_src/python_types/tutorial008b.py!}
{!> ../../docs_src/python_types/tutorial008b.py!}
```
////
@@ -321,7 +321,7 @@ Python 3.10-এ একটি **নতুন সিনট্যাক্স** আ
Python 3.6 এবং তার উপরের সংস্করণগুলিতে (Python 3.10 অনতর্ভুক্ত) আপনি `typing` মডিউল থেকে `Optional` ইমপোর্ট করে এটি ঘোষণা এবং ব্যবহার করতে পারেন।
```Python hl_lines="1 4"
{!../../../docs_src/python_types/tutorial009.py!}
{!../../docs_src/python_types/tutorial009.py!}
```
`Optional[str]` ব্যবহার করা মানে হল শুধু `str` নয়, এটি হতে পারে `None`-ও, যা আপনার এডিটরকে সেই ত্রুটিগুলি শনাক্ত করতে সাহায্য করবে যেখানে আপনি ধরে নিচ্ছেন যে একটি মান সবসময় `str` হবে, অথচ এটি `None`-ও হতে পারেও।
@@ -333,7 +333,7 @@ Python 3.6 এবং তার উপরের সংস্করণগুলি
//// tab | Python 3.10+
```Python hl_lines="1"
{!> ../../../docs_src/python_types/tutorial009_py310.py!}
{!> ../../docs_src/python_types/tutorial009_py310.py!}
```
////
@@ -341,7 +341,7 @@ Python 3.6 এবং তার উপরের সংস্করণগুলি
//// tab | Python 3.8+
```Python hl_lines="1 4"
{!> ../../../docs_src/python_types/tutorial009.py!}
{!> ../../docs_src/python_types/tutorial009.py!}
```
////
@@ -349,7 +349,7 @@ Python 3.6 এবং তার উপরের সংস্করণগুলি
//// tab | Python 3.8+ বিকল্প
```Python hl_lines="1 4"
{!> ../../../docs_src/python_types/tutorial009b.py!}
{!> ../../docs_src/python_types/tutorial009b.py!}
```
////
@@ -370,7 +370,7 @@ Python 3.6 এবং তার উপরের সংস্করণগুলি
একটি উদাহরণ হিসেবে, এই ফাংশনটি নিন:
```Python hl_lines="1 4"
{!../../../docs_src/python_types/tutorial009c.py!}
{!../../docs_src/python_types/tutorial009c.py!}
```
`name` প্যারামিটারটি `Optional[str]` হিসেবে সংজ্ঞায়িত হয়েছে, কিন্তু এটি **অপশনাল নয়**, আপনি প্যারামিটার ছাড়া ফাংশনটি কল করতে পারবেন না:
@@ -388,7 +388,7 @@ say_hi(name=None) # এটি কাজ করে, None বৈধ 🎉
সুখবর হল, একবার আপনি Python 3.10 ব্যবহার করা শুরু করলে, আপনাকে এগুলোর ব্যাপারে আর চিন্তা করতে হবে না, যেহুতু আপনি | ব্যবহার করেই ইউনিয়ন ঘোষণা করতে পারবেন:
```Python hl_lines="1 4"
{!../../../docs_src/python_types/tutorial009c_py310.py!}
{!../../docs_src/python_types/tutorial009c_py310.py!}
```
এবং তারপর আপনাকে নামগুলি যেমন `Optional` এবং `Union` নিয়ে আর চিন্তা করতে হবে না। 😎
@@ -452,13 +452,13 @@ Python 3.10-এ, `Union` এবং `Optional` জেনেরিকস ব্য
ধরুন আপনার কাছে `Person` নামে একটি ক্লাস আছে, যার একটি নাম আছে:
```Python hl_lines="1-3"
{!../../../docs_src/python_types/tutorial010.py!}
{!../../docs_src/python_types/tutorial010.py!}
```
তারপর আপনি একটি ভেরিয়েবলকে `Person` টাইপের হিসেবে ঘোষণা করতে পারেন:
```Python hl_lines="6"
{!../../../docs_src/python_types/tutorial010.py!}
{!../../docs_src/python_types/tutorial010.py!}
```
এবং তারপর, আবার, আপনি এডিটর সাপোর্ট পেয়ে যাবেন:
@@ -486,7 +486,7 @@ Python 3.10-এ, `Union` এবং `Optional` জেনেরিকস ব্য
//// tab | Python 3.10+
```Python
{!> ../../../docs_src/python_types/tutorial011_py310.py!}
{!> ../../docs_src/python_types/tutorial011_py310.py!}
```
////
@@ -494,7 +494,7 @@ Python 3.10-এ, `Union` এবং `Optional` জেনেরিকস ব্য
//// tab | Python 3.9+
```Python
{!> ../../../docs_src/python_types/tutorial011_py39.py!}
{!> ../../docs_src/python_types/tutorial011_py39.py!}
```
////
@@ -502,7 +502,7 @@ Python 3.10-এ, `Union` এবং `Optional` জেনেরিকস ব্য
//// tab | Python 3.8+
```Python
{!> ../../../docs_src/python_types/tutorial011.py!}
{!> ../../docs_src/python_types/tutorial011.py!}
```
////
@@ -532,7 +532,7 @@ Python-এ এমন একটি ফিচার আছে যা `Annotated`
Python 3.9-এ, `Annotated` স্ট্যান্ডার্ড লাইব্রেরিতে অন্তর্ভুক্ত, তাই আপনি এটি `typing` থেকে ইমপোর্ট করতে পারেন।
```Python hl_lines="1 4"
{!> ../../../docs_src/python_types/tutorial013_py39.py!}
{!> ../../docs_src/python_types/tutorial013_py39.py!}
```
////
@@ -544,7 +544,7 @@ Python 3.9-এর নীচের সংস্করণগুলিতে, আ
এটি **FastAPI** এর সাথে ইতিমদ্ধে ইনস্টল হয়ে থাকবে।
```Python hl_lines="1 4"
{!> ../../../docs_src/python_types/tutorial013.py!}
{!> ../../docs_src/python_types/tutorial013.py!}
```
////

View File

@@ -27,7 +27,7 @@ Jedes dieser Response-`dict`s kann einen Schlüssel `model` haben, welcher ein P
Um beispielsweise eine weitere Response mit dem Statuscode `404` und einem Pydantic-Modell `Message` zu deklarieren, können Sie schreiben:
```Python hl_lines="18 22"
{!../../../docs_src/additional_responses/tutorial001.py!}
{!../../docs_src/additional_responses/tutorial001.py!}
```
/// note | "Hinweis"
@@ -178,7 +178,7 @@ Sie können denselben `responses`-Parameter verwenden, um verschiedene Medientyp
Sie können beispielsweise einen zusätzlichen Medientyp `image/png` hinzufügen und damit deklarieren, dass Ihre *Pfadoperation* ein JSON-Objekt (mit dem Medientyp `application/json`) oder ein PNG-Bild zurückgeben kann:
```Python hl_lines="19-24 28"
{!../../../docs_src/additional_responses/tutorial002.py!}
{!../../docs_src/additional_responses/tutorial002.py!}
```
/// note | "Hinweis"
@@ -208,7 +208,7 @@ Sie können beispielsweise eine Response mit dem Statuscode `404` deklarieren, d
Und eine Response mit dem Statuscode `200`, die Ihr `response_model` verwendet, aber ein benutzerdefiniertes Beispiel (`example`) enthält:
```Python hl_lines="20-31"
{!../../../docs_src/additional_responses/tutorial003.py!}
{!../../docs_src/additional_responses/tutorial003.py!}
```
Es wird alles kombiniert und in Ihre OpenAPI eingebunden und in der API-Dokumentation angezeigt:
@@ -244,7 +244,7 @@ Mit dieser Technik können Sie einige vordefinierte Responses in Ihren *Pfadoper
Zum Beispiel:
```Python hl_lines="13-17 26"
{!../../../docs_src/additional_responses/tutorial004.py!}
{!../../docs_src/additional_responses/tutorial004.py!}
```
## Weitere Informationen zu OpenAPI-Responses

View File

@@ -17,7 +17,7 @@ Um dies zu erreichen, importieren Sie `JSONResponse`, und geben Sie Ihren Inhalt
//// tab | Python 3.10+
```Python hl_lines="4 25"
{!> ../../../docs_src/additional_status_codes/tutorial001_an_py310.py!}
{!> ../../docs_src/additional_status_codes/tutorial001_an_py310.py!}
```
////
@@ -25,7 +25,7 @@ Um dies zu erreichen, importieren Sie `JSONResponse`, und geben Sie Ihren Inhalt
//// tab | Python 3.9+
```Python hl_lines="4 25"
{!> ../../../docs_src/additional_status_codes/tutorial001_an_py39.py!}
{!> ../../docs_src/additional_status_codes/tutorial001_an_py39.py!}
```
////
@@ -33,7 +33,7 @@ Um dies zu erreichen, importieren Sie `JSONResponse`, und geben Sie Ihren Inhalt
//// tab | Python 3.8+
```Python hl_lines="4 26"
{!> ../../../docs_src/additional_status_codes/tutorial001_an.py!}
{!> ../../docs_src/additional_status_codes/tutorial001_an.py!}
```
////
@@ -47,7 +47,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="2 23"
{!> ../../../docs_src/additional_status_codes/tutorial001_py310.py!}
{!> ../../docs_src/additional_status_codes/tutorial001_py310.py!}
```
////
@@ -61,7 +61,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="4 25"
{!> ../../../docs_src/additional_status_codes/tutorial001.py!}
{!> ../../docs_src/additional_status_codes/tutorial001.py!}
```
////

View File

@@ -21,7 +21,7 @@ Dazu deklarieren wir eine Methode `__call__`:
//// tab | Python 3.9+
```Python hl_lines="12"
{!> ../../../docs_src/dependencies/tutorial011_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial011_an_py39.py!}
```
////
@@ -29,7 +29,7 @@ Dazu deklarieren wir eine Methode `__call__`:
//// tab | Python 3.8+
```Python hl_lines="11"
{!> ../../../docs_src/dependencies/tutorial011_an.py!}
{!> ../../docs_src/dependencies/tutorial011_an.py!}
```
////
@@ -43,7 +43,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="10"
{!> ../../../docs_src/dependencies/tutorial011.py!}
{!> ../../docs_src/dependencies/tutorial011.py!}
```
////
@@ -57,7 +57,7 @@ Und jetzt können wir `__init__` verwenden, um die Parameter der Instanz zu dekl
//// tab | Python 3.9+
```Python hl_lines="9"
{!> ../../../docs_src/dependencies/tutorial011_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial011_an_py39.py!}
```
////
@@ -65,7 +65,7 @@ Und jetzt können wir `__init__` verwenden, um die Parameter der Instanz zu dekl
//// tab | Python 3.8+
```Python hl_lines="8"
{!> ../../../docs_src/dependencies/tutorial011_an.py!}
{!> ../../docs_src/dependencies/tutorial011_an.py!}
```
////
@@ -79,7 +79,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7"
{!> ../../../docs_src/dependencies/tutorial011.py!}
{!> ../../docs_src/dependencies/tutorial011.py!}
```
////
@@ -93,7 +93,7 @@ Wir könnten eine Instanz dieser Klasse erstellen mit:
//// tab | Python 3.9+
```Python hl_lines="18"
{!> ../../../docs_src/dependencies/tutorial011_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial011_an_py39.py!}
```
////
@@ -101,7 +101,7 @@ Wir könnten eine Instanz dieser Klasse erstellen mit:
//// tab | Python 3.8+
```Python hl_lines="17"
{!> ../../../docs_src/dependencies/tutorial011_an.py!}
{!> ../../docs_src/dependencies/tutorial011_an.py!}
```
////
@@ -115,7 +115,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="16"
{!> ../../../docs_src/dependencies/tutorial011.py!}
{!> ../../docs_src/dependencies/tutorial011.py!}
```
////
@@ -137,7 +137,7 @@ checker(q="somequery")
//// tab | Python 3.9+
```Python hl_lines="22"
{!> ../../../docs_src/dependencies/tutorial011_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial011_an_py39.py!}
```
////
@@ -145,7 +145,7 @@ checker(q="somequery")
//// tab | Python 3.8+
```Python hl_lines="21"
{!> ../../../docs_src/dependencies/tutorial011_an.py!}
{!> ../../docs_src/dependencies/tutorial011_an.py!}
```
////
@@ -159,7 +159,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="20"
{!> ../../../docs_src/dependencies/tutorial011.py!}
{!> ../../docs_src/dependencies/tutorial011.py!}
```
////

View File

@@ -33,13 +33,13 @@ Betrachten wir als einfaches Beispiel eine Dateistruktur ähnlich der in [Größ
Die Datei `main.py` hätte als Inhalt:
```Python
{!../../../docs_src/async_tests/main.py!}
{!../../docs_src/async_tests/main.py!}
```
Die Datei `test_main.py` hätte die Tests für `main.py`, das könnte jetzt so aussehen:
```Python
{!../../../docs_src/async_tests/test_main.py!}
{!../../docs_src/async_tests/test_main.py!}
```
## Es ausführen
@@ -61,7 +61,7 @@ $ pytest
Der Marker `@pytest.mark.anyio` teilt pytest mit, dass diese Testfunktion asynchron aufgerufen werden soll:
```Python hl_lines="7"
{!../../../docs_src/async_tests/test_main.py!}
{!../../docs_src/async_tests/test_main.py!}
```
/// tip | "Tipp"
@@ -73,7 +73,7 @@ Beachten Sie, dass die Testfunktion jetzt `async def` ist und nicht nur `def` wi
Dann können wir einen `AsyncClient` mit der App erstellen und mit `await` asynchrone Requests an ihn senden.
```Python hl_lines="9-12"
{!../../../docs_src/async_tests/test_main.py!}
{!../../docs_src/async_tests/test_main.py!}
```
Das ist das Äquivalent zu:

View File

@@ -19,7 +19,7 @@ In diesem Fall würde der ursprüngliche Pfad `/app` tatsächlich unter `/api/v1
Auch wenn Ihr gesamter Code unter der Annahme geschrieben ist, dass es nur `/app` gibt.
```Python hl_lines="6"
{!../../../docs_src/behind_a_proxy/tutorial001.py!}
{!../../docs_src/behind_a_proxy/tutorial001.py!}
```
Und der Proxy würde das **Pfadpräfix** on-the-fly **"entfernen**", bevor er die Anfrage an Uvicorn übermittelt, dafür sorgend, dass Ihre Anwendung davon überzeugt ist, dass sie unter `/app` bereitgestellt wird, sodass Sie nicht Ihren gesamten Code dahingehend aktualisieren müssen, das Präfix `/api/v1` zu verwenden.
@@ -99,7 +99,7 @@ Sie können den aktuellen `root_path` abrufen, der von Ihrer Anwendung für jede
Hier fügen wir ihn, nur zu Demonstrationszwecken, in die Nachricht ein.
```Python hl_lines="8"
{!../../../docs_src/behind_a_proxy/tutorial001.py!}
{!../../docs_src/behind_a_proxy/tutorial001.py!}
```
Wenn Sie Uvicorn dann starten mit:
@@ -128,7 +128,7 @@ wäre die Response etwa:
Falls Sie keine Möglichkeit haben, eine Kommandozeilenoption wie `--root-path` oder ähnlich zu übergeben, können Sie als Alternative beim Erstellen Ihrer FastAPI-Anwendung den Parameter `root_path` setzen:
```Python hl_lines="3"
{!../../../docs_src/behind_a_proxy/tutorial002.py!}
{!../../docs_src/behind_a_proxy/tutorial002.py!}
```
Die Übergabe des `root_path` an `FastAPI` wäre das Äquivalent zur Übergabe der `--root-path`-Kommandozeilenoption an Uvicorn oder Hypercorn.
@@ -310,7 +310,7 @@ Wenn Sie eine benutzerdefinierte Liste von Servern (`servers`) übergeben und es
Zum Beispiel:
```Python hl_lines="4-7"
{!../../../docs_src/behind_a_proxy/tutorial003.py!}
{!../../docs_src/behind_a_proxy/tutorial003.py!}
```
Erzeugt ein OpenAPI-Schema, wie:
@@ -359,7 +359,7 @@ Die Dokumentationsoberfläche interagiert mit dem von Ihnen ausgewählten Server
Wenn Sie nicht möchten, dass **FastAPI** einen automatischen Server inkludiert, welcher `root_path` verwendet, können Sie den Parameter `root_path_in_servers=False` verwenden:
```Python hl_lines="9"
{!../../../docs_src/behind_a_proxy/tutorial004.py!}
{!../../docs_src/behind_a_proxy/tutorial004.py!}
```
Dann wird er nicht in das OpenAPI-Schema aufgenommen.

View File

@@ -31,7 +31,7 @@ Das liegt daran, dass FastAPI standardmäßig jedes enthaltene Element überprü
Wenn Sie jedoch sicher sind, dass der von Ihnen zurückgegebene Inhalt **mit JSON serialisierbar** ist, können Sie ihn direkt an die Response-Klasse übergeben und die zusätzliche Arbeit vermeiden, die FastAPI hätte, indem es Ihren zurückgegebenen Inhalt durch den `jsonable_encoder` leitet, bevor es ihn an die Response-Klasse übergibt.
```Python hl_lines="2 7"
{!../../../docs_src/custom_response/tutorial001b.py!}
{!../../docs_src/custom_response/tutorial001b.py!}
```
/// info
@@ -58,7 +58,7 @@ Um eine Response mit HTML direkt von **FastAPI** zurückzugeben, verwenden Sie `
* Übergeben Sie `HTMLResponse` als den Parameter `response_class` Ihres *Pfadoperation-Dekorators*.
```Python hl_lines="2 7"
{!../../../docs_src/custom_response/tutorial002.py!}
{!../../docs_src/custom_response/tutorial002.py!}
```
/// info
@@ -78,7 +78,7 @@ Wie in [Eine Response direkt zurückgeben](response-directly.md){.internal-link
Das gleiche Beispiel von oben, das eine `HTMLResponse` zurückgibt, könnte so aussehen:
```Python hl_lines="2 7 19"
{!../../../docs_src/custom_response/tutorial003.py!}
{!../../docs_src/custom_response/tutorial003.py!}
```
/// warning | "Achtung"
@@ -104,7 +104,7 @@ Die `response_class` wird dann nur zur Dokumentation der OpenAPI-Pfadoperation*
Es könnte zum Beispiel so etwas sein:
```Python hl_lines="7 21 23"
{!../../../docs_src/custom_response/tutorial004.py!}
{!../../docs_src/custom_response/tutorial004.py!}
```
In diesem Beispiel generiert die Funktion `generate_html_response()` bereits eine `Response` und gibt sie zurück, anstatt das HTML in einem `str` zurückzugeben.
@@ -145,7 +145,7 @@ Sie akzeptiert die folgenden Parameter:
FastAPI (eigentlich Starlette) fügt automatisch einen Content-Length-Header ein. Außerdem wird es einen Content-Type-Header einfügen, der auf dem media_type basiert, und für Texttypen einen Zeichensatz (charset) anfügen.
```Python hl_lines="1 18"
{!../../../docs_src/response_directly/tutorial002.py!}
{!../../docs_src/response_directly/tutorial002.py!}
```
### `HTMLResponse`
@@ -157,7 +157,7 @@ Nimmt Text oder Bytes entgegen und gibt eine HTML-Response zurück, wie Sie oben
Nimmt Text oder Bytes entgegen und gibt eine Plain-Text-Response zurück.
```Python hl_lines="2 7 9"
{!../../../docs_src/custom_response/tutorial005.py!}
{!../../docs_src/custom_response/tutorial005.py!}
```
### `JSONResponse`
@@ -181,7 +181,7 @@ Eine alternative JSON-Response mit <a href="https://github.com/ultrajson/ultrajs
///
```Python hl_lines="2 7"
{!../../../docs_src/custom_response/tutorial001.py!}
{!../../docs_src/custom_response/tutorial001.py!}
```
/// tip | "Tipp"
@@ -197,7 +197,7 @@ Gibt eine HTTP-Weiterleitung (HTTP-Redirect) zurück. Verwendet standardmäßig
Sie können eine `RedirectResponse` direkt zurückgeben:
```Python hl_lines="2 9"
{!../../../docs_src/custom_response/tutorial006.py!}
{!../../docs_src/custom_response/tutorial006.py!}
```
---
@@ -206,7 +206,7 @@ Oder Sie können sie im Parameter `response_class` verwenden:
```Python hl_lines="2 7 9"
{!../../../docs_src/custom_response/tutorial006b.py!}
{!../../docs_src/custom_response/tutorial006b.py!}
```
Wenn Sie das tun, können Sie die URL direkt von Ihrer *Pfadoperation*-Funktion zurückgeben.
@@ -218,7 +218,7 @@ In diesem Fall ist der verwendete `status_code` der Standardcode für die `Redir
Sie können den Parameter `status_code` auch in Kombination mit dem Parameter `response_class` verwenden:
```Python hl_lines="2 7 9"
{!../../../docs_src/custom_response/tutorial006c.py!}
{!../../docs_src/custom_response/tutorial006c.py!}
```
### `StreamingResponse`
@@ -226,7 +226,7 @@ Sie können den Parameter `status_code` auch in Kombination mit dem Parameter `r
Nimmt einen asynchronen Generator oder einen normalen Generator/Iterator und streamt den Responsebody.
```Python hl_lines="2 14"
{!../../../docs_src/custom_response/tutorial007.py!}
{!../../docs_src/custom_response/tutorial007.py!}
```
#### Verwendung von `StreamingResponse` mit dateiähnlichen Objekten
@@ -238,7 +238,7 @@ Auf diese Weise müssen Sie nicht alles zuerst in den Arbeitsspeicher lesen und
Das umfasst viele Bibliotheken zur Interaktion mit Cloud-Speicher, Videoverarbeitung und anderen.
```{ .python .annotate hl_lines="2 10-12 14" }
{!../../../docs_src/custom_response/tutorial008.py!}
{!../../docs_src/custom_response/tutorial008.py!}
```
1. Das ist die Generatorfunktion. Es handelt sich um eine „Generatorfunktion“, da sie `yield`-Anweisungen enthält.
@@ -269,13 +269,13 @@ Nimmt zur Instanziierung einen anderen Satz von Argumenten entgegen als die ande
Datei-Responses enthalten die entsprechenden `Content-Length`-, `Last-Modified`- und `ETag`-Header.
```Python hl_lines="2 10"
{!../../../docs_src/custom_response/tutorial009.py!}
{!../../docs_src/custom_response/tutorial009.py!}
```
Sie können auch den Parameter `response_class` verwenden:
```Python hl_lines="2 8 10"
{!../../../docs_src/custom_response/tutorial009b.py!}
{!../../docs_src/custom_response/tutorial009b.py!}
```
In diesem Fall können Sie den Dateipfad direkt von Ihrer *Pfadoperation*-Funktion zurückgeben.
@@ -291,7 +291,7 @@ Sie möchten etwa, dass Ihre Response eingerücktes und formatiertes JSON zurüc
Sie könnten eine `CustomORJSONResponse` erstellen. Das Wichtigste, was Sie tun müssen, ist, eine `Response.render(content)`-Methode zu erstellen, die den Inhalt als `bytes` zurückgibt:
```Python hl_lines="9-14 17"
{!../../../docs_src/custom_response/tutorial009c.py!}
{!../../docs_src/custom_response/tutorial009c.py!}
```
Statt:
@@ -319,7 +319,7 @@ Der Parameter, der das definiert, ist `default_response_class`.
Im folgenden Beispiel verwendet **FastAPI** standardmäßig `ORJSONResponse` in allen *Pfadoperationen*, anstelle von `JSONResponse`.
```Python hl_lines="2 4"
{!../../../docs_src/custom_response/tutorial010.py!}
{!../../docs_src/custom_response/tutorial010.py!}
```
/// tip | "Tipp"

View File

@@ -5,7 +5,7 @@ FastAPI basiert auf **Pydantic** und ich habe Ihnen gezeigt, wie Sie Pydantic-Mo
Aber FastAPI unterstützt auf die gleiche Weise auch die Verwendung von <a href="https://docs.python.org/3/library/dataclasses.html" class="external-link" target="_blank">`dataclasses`</a>:
```Python hl_lines="1 7-12 19-20"
{!../../../docs_src/dataclasses/tutorial001.py!}
{!../../docs_src/dataclasses/tutorial001.py!}
```
Das ist dank **Pydantic** ebenfalls möglich, da es <a href="https://pydantic-docs.helpmanual.io/usage/dataclasses/#use-of-stdlib-dataclasses-with-basemodel" class="external-link" target="_blank">`dataclasses` intern unterstützt</a>.
@@ -35,7 +35,7 @@ Wenn Sie jedoch eine Menge Datenklassen herumliegen haben, ist dies ein guter Tr
Sie können `dataclasses` auch im Parameter `response_model` verwenden:
```Python hl_lines="1 7-13 19"
{!../../../docs_src/dataclasses/tutorial002.py!}
{!../../docs_src/dataclasses/tutorial002.py!}
```
Die Datenklasse wird automatisch in eine Pydantic-Datenklasse konvertiert.
@@ -53,7 +53,7 @@ In einigen Fällen müssen Sie möglicherweise immer noch Pydantics Version von
In diesem Fall können Sie einfach die Standard-`dataclasses` durch `pydantic.dataclasses` ersetzen, was einen direkten Ersatz darstellt:
```{ .python .annotate hl_lines="1 5 8-11 14-17 23-25 28" }
{!../../../docs_src/dataclasses/tutorial003.py!}
{!../../docs_src/dataclasses/tutorial003.py!}
```
1. Wir importieren `field` weiterhin von Standard-`dataclasses`.

View File

@@ -31,7 +31,7 @@ Beginnen wir mit einem Beispiel und sehen es uns dann im Detail an.
Wir erstellen eine asynchrone Funktion `lifespan()` mit `yield` wie folgt:
```Python hl_lines="16 19"
{!../../../docs_src/events/tutorial003.py!}
{!../../docs_src/events/tutorial003.py!}
```
Hier simulieren wir das langsame *Hochfahren*, das Laden des Modells, indem wir die (Fake-)Modellfunktion vor dem `yield` in das Dictionary mit Modellen für maschinelles Lernen einfügen. Dieser Code wird ausgeführt, **bevor** die Anwendung **beginnt, Requests entgegenzunehmen**, während des *Hochfahrens*.
@@ -51,7 +51,7 @@ Möglicherweise müssen Sie eine neue Version starten, oder Sie haben es einfach
Das Erste, was auffällt, ist, dass wir eine asynchrone Funktion mit `yield` definieren. Das ist sehr ähnlich zu Abhängigkeiten mit `yield`.
```Python hl_lines="14-19"
{!../../../docs_src/events/tutorial003.py!}
{!../../docs_src/events/tutorial003.py!}
```
Der erste Teil der Funktion, vor dem `yield`, wird ausgeführt **bevor** die Anwendung startet.
@@ -65,7 +65,7 @@ Wie Sie sehen, ist die Funktion mit einem `@asynccontextmanager` versehen.
Dadurch wird die Funktion in einen sogenannten „**asynchronen Kontextmanager**“ umgewandelt.
```Python hl_lines="1 13"
{!../../../docs_src/events/tutorial003.py!}
{!../../docs_src/events/tutorial003.py!}
```
Ein **Kontextmanager** in Python ist etwas, das Sie in einer `with`-Anweisung verwenden können, zum Beispiel kann `open()` als Kontextmanager verwendet werden:
@@ -89,7 +89,7 @@ In unserem obigen Codebeispiel verwenden wir ihn nicht direkt, sondern übergebe
Der Parameter `lifespan` der `FastAPI`-App benötigt einen **asynchronen Kontextmanager**, wir können ihm also unseren neuen asynchronen Kontextmanager `lifespan` übergeben.
```Python hl_lines="22"
{!../../../docs_src/events/tutorial003.py!}
{!../../docs_src/events/tutorial003.py!}
```
## Alternative Events (deprecated)
@@ -113,7 +113,7 @@ Diese Funktionen können mit `async def` oder normalem `def` deklariert werden.
Um eine Funktion hinzuzufügen, die vor dem Start der Anwendung ausgeführt werden soll, deklarieren Sie diese mit dem Event `startup`:
```Python hl_lines="8"
{!../../../docs_src/events/tutorial001.py!}
{!../../docs_src/events/tutorial001.py!}
```
In diesem Fall initialisiert die Eventhandler-Funktion `startup` die „Datenbank“ der Items (nur ein `dict`) mit einigen Werten.
@@ -127,7 +127,7 @@ Und Ihre Anwendung empfängt erst dann Anfragen, wenn alle `startup`-Eventhandle
Um eine Funktion hinzuzufügen, die beim Herunterfahren der Anwendung ausgeführt werden soll, deklarieren Sie sie mit dem Event `shutdown`:
```Python hl_lines="6"
{!../../../docs_src/events/tutorial002.py!}
{!../../docs_src/events/tutorial002.py!}
```
Hier schreibt die `shutdown`-Eventhandler-Funktion eine Textzeile `"Application shutdown"` in eine Datei `log.txt`.

View File

@@ -31,7 +31,7 @@ Beginnen wir mit einer einfachen FastAPI-Anwendung:
//// tab | Python 3.9+
```Python hl_lines="7-9 12-13 16-17 21"
{!> ../../../docs_src/generate_clients/tutorial001_py39.py!}
{!> ../../docs_src/generate_clients/tutorial001_py39.py!}
```
////
@@ -39,7 +39,7 @@ Beginnen wir mit einer einfachen FastAPI-Anwendung:
//// tab | Python 3.8+
```Python hl_lines="9-11 14-15 18 19 23"
{!> ../../../docs_src/generate_clients/tutorial001.py!}
{!> ../../docs_src/generate_clients/tutorial001.py!}
```
////
@@ -150,7 +150,7 @@ Beispielsweise könnten Sie einen Abschnitt für **Items (Artikel)** und einen w
//// tab | Python 3.9+
```Python hl_lines="21 26 34"
{!> ../../../docs_src/generate_clients/tutorial002_py39.py!}
{!> ../../docs_src/generate_clients/tutorial002_py39.py!}
```
////
@@ -158,7 +158,7 @@ Beispielsweise könnten Sie einen Abschnitt für **Items (Artikel)** und einen w
//// tab | Python 3.8+
```Python hl_lines="23 28 36"
{!> ../../../docs_src/generate_clients/tutorial002.py!}
{!> ../../docs_src/generate_clients/tutorial002.py!}
```
////
@@ -211,7 +211,7 @@ Anschließend können Sie diese benutzerdefinierte Funktion als Parameter `gener
//// tab | Python 3.9+
```Python hl_lines="6-7 10"
{!> ../../../docs_src/generate_clients/tutorial003_py39.py!}
{!> ../../docs_src/generate_clients/tutorial003_py39.py!}
```
////
@@ -219,7 +219,7 @@ Anschließend können Sie diese benutzerdefinierte Funktion als Parameter `gener
//// tab | Python 3.8+
```Python hl_lines="8-9 12"
{!> ../../../docs_src/generate_clients/tutorial003.py!}
{!> ../../docs_src/generate_clients/tutorial003.py!}
```
////
@@ -247,7 +247,7 @@ Wir könnten das OpenAPI-JSON in eine Datei `openapi.json` herunterladen und dan
//// tab | Python
```Python
{!> ../../../docs_src/generate_clients/tutorial004.py!}
{!> ../../docs_src/generate_clients/tutorial004.py!}
```
////
@@ -255,7 +255,7 @@ Wir könnten das OpenAPI-JSON in eine Datei `openapi.json` herunterladen und dan
//// tab | Node.js
```Javascript
{!> ../../../docs_src/generate_clients/tutorial004.js!}
{!> ../../docs_src/generate_clients/tutorial004.js!}
```
////

View File

@@ -58,7 +58,7 @@ Erzwingt, dass alle eingehenden Requests entweder `https` oder `wss` sein müsse
Alle eingehenden Requests an `http` oder `ws` werden stattdessen an das sichere Schema umgeleitet.
```Python hl_lines="2 6"
{!../../../docs_src/advanced_middleware/tutorial001.py!}
{!../../docs_src/advanced_middleware/tutorial001.py!}
```
## `TrustedHostMiddleware`
@@ -66,7 +66,7 @@ Alle eingehenden Requests an `http` oder `ws` werden stattdessen an das sichere
Erzwingt, dass alle eingehenden Requests einen korrekt gesetzten `Host`-Header haben, um sich vor HTTP-Host-Header-Angriffen zu schützen.
```Python hl_lines="2 6-8"
{!../../../docs_src/advanced_middleware/tutorial002.py!}
{!../../docs_src/advanced_middleware/tutorial002.py!}
```
Die folgenden Argumente werden unterstützt:
@@ -82,7 +82,7 @@ Verarbeitet GZip-Responses für alle Requests, die `"gzip"` im `Accept-Encoding`
Diese Middleware verarbeitet sowohl Standard- als auch Streaming-Responses.
```Python hl_lines="2 6"
{!../../../docs_src/advanced_middleware/tutorial003.py!}
{!../../docs_src/advanced_middleware/tutorial003.py!}
```
Die folgenden Argumente werden unterstützt:

View File

@@ -32,7 +32,7 @@ Sie verfügt über eine *Pfadoperation*, die einen `Invoice`-Body empfängt, und
Dieser Teil ist ziemlich normal, der größte Teil des Codes ist Ihnen wahrscheinlich bereits bekannt:
```Python hl_lines="9-13 36-53"
{!../../../docs_src/openapi_callbacks/tutorial001.py!}
{!../../docs_src/openapi_callbacks/tutorial001.py!}
```
/// tip | "Tipp"
@@ -93,7 +93,7 @@ Wenn Sie diese Sichtweise (des *externen Entwicklers*) vorübergehend übernehme
Erstellen Sie zunächst einen neuen `APIRouter`, der einen oder mehrere Callbacks enthält.
```Python hl_lines="3 25"
{!../../../docs_src/openapi_callbacks/tutorial001.py!}
{!../../docs_src/openapi_callbacks/tutorial001.py!}
```
### Die Callback-*Pfadoperation* erstellen
@@ -106,7 +106,7 @@ Sie sollte wie eine normale FastAPI-*Pfadoperation* aussehen:
* Und sie könnte auch eine Deklaration der Response enthalten, die zurückgegeben werden soll, z. B. `response_model=InvoiceEventReceived`.
```Python hl_lines="16-18 21-22 28-32"
{!../../../docs_src/openapi_callbacks/tutorial001.py!}
{!../../docs_src/openapi_callbacks/tutorial001.py!}
```
Es gibt zwei Hauptunterschiede zu einer normalen *Pfadoperation*:
@@ -176,7 +176,7 @@ An diesem Punkt haben Sie die benötigte(n) *Callback-Pfadoperation(en)* (diejen
Verwenden Sie nun den Parameter `callbacks` im *Pfadoperation-Dekorator Ihrer API*, um das Attribut `.routes` (das ist eigentlich nur eine `list`e von Routen/*Pfadoperationen*) dieses Callback-Routers zu übergeben:
```Python hl_lines="35"
{!../../../docs_src/openapi_callbacks/tutorial001.py!}
{!../../docs_src/openapi_callbacks/tutorial001.py!}
```
/// tip | "Tipp"

View File

@@ -33,7 +33,7 @@ Webhooks sind in OpenAPI 3.1.0 und höher verfügbar und werden von FastAPI `0.9
Wenn Sie eine **FastAPI**-Anwendung erstellen, gibt es ein `webhooks`-Attribut, mit dem Sie *Webhooks* definieren können, genauso wie Sie *Pfadoperationen* definieren würden, zum Beispiel mit `@app.webhooks.post()`.
```Python hl_lines="9-13 36-53"
{!../../../docs_src/openapi_webhooks/tutorial001.py!}
{!../../docs_src/openapi_webhooks/tutorial001.py!}
```
Die von Ihnen definierten Webhooks landen im **OpenAPI**-Schema und der automatischen **Dokumentations-Oberfläche**.

View File

@@ -13,7 +13,7 @@ Mit dem Parameter `operation_id` können Sie die OpenAPI `operationId` festlegen
Sie müssten sicherstellen, dass sie für jede Operation eindeutig ist.
```Python hl_lines="6"
{!../../../docs_src/path_operation_advanced_configuration/tutorial001.py!}
{!../../docs_src/path_operation_advanced_configuration/tutorial001.py!}
```
### Verwendung des Namens der *Pfadoperation-Funktion* als operationId
@@ -23,7 +23,7 @@ Wenn Sie die Funktionsnamen Ihrer API als `operationId`s verwenden möchten, kö
Sie sollten dies tun, nachdem Sie alle Ihre *Pfadoperationen* hinzugefügt haben.
```Python hl_lines="2 12-21 24"
{!../../../docs_src/path_operation_advanced_configuration/tutorial002.py!}
{!../../docs_src/path_operation_advanced_configuration/tutorial002.py!}
```
/// tip | "Tipp"
@@ -45,7 +45,7 @@ Auch wenn diese sich in unterschiedlichen Modulen (Python-Dateien) befinden.
Um eine *Pfadoperation* aus dem generierten OpenAPI-Schema (und damit aus den automatischen Dokumentationssystemen) auszuschließen, verwenden Sie den Parameter `include_in_schema` und setzen Sie ihn auf `False`:
```Python hl_lines="6"
{!../../../docs_src/path_operation_advanced_configuration/tutorial003.py!}
{!../../docs_src/path_operation_advanced_configuration/tutorial003.py!}
```
## Fortgeschrittene Beschreibung mittels Docstring
@@ -57,7 +57,7 @@ Das Hinzufügen eines `\f` (ein maskiertes „Form Feed“-Zeichen) führt dazu,
Sie wird nicht in der Dokumentation angezeigt, aber andere Tools (z. B. Sphinx) können den Rest verwenden.
```Python hl_lines="19-29"
{!../../../docs_src/path_operation_advanced_configuration/tutorial004.py!}
{!../../docs_src/path_operation_advanced_configuration/tutorial004.py!}
```
## Zusätzliche Responses
@@ -101,7 +101,7 @@ Sie können das OpenAPI-Schema für eine *Pfadoperation* erweitern, indem Sie de
Dieses `openapi_extra` kann beispielsweise hilfreich sein, um <a href="https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specificationExtensions" class="external-link" target="_blank">OpenAPI-Erweiterungen</a> zu deklarieren:
```Python hl_lines="6"
{!../../../docs_src/path_operation_advanced_configuration/tutorial005.py!}
{!../../docs_src/path_operation_advanced_configuration/tutorial005.py!}
```
Wenn Sie die automatische API-Dokumentation öffnen, wird Ihre Erweiterung am Ende der spezifischen *Pfadoperation* angezeigt.
@@ -150,7 +150,7 @@ Sie könnten sich beispielsweise dafür entscheiden, den Request mit Ihrem eigen
Das könnte man mit `openapi_extra` machen:
```Python hl_lines="20-37 39-40"
{!../../../docs_src/path_operation_advanced_configuration/tutorial006.py!}
{!../../docs_src/path_operation_advanced_configuration/tutorial006.py!}
```
In diesem Beispiel haben wir kein Pydantic-Modell deklariert. Tatsächlich wird der Requestbody nicht einmal als JSON <abbr title="von einem einfachen Format, wie Bytes, in Python-Objekte konvertieren">geparst</abbr>, sondern direkt als `bytes` gelesen und die Funktion `magic_data_reader ()` wäre dafür verantwortlich, ihn in irgendeiner Weise zu parsen.
@@ -168,7 +168,7 @@ In der folgenden Anwendung verwenden wir beispielsweise weder die integrierte Fu
//// tab | Pydantic v2
```Python hl_lines="17-22 24"
{!> ../../../docs_src/path_operation_advanced_configuration/tutorial007.py!}
{!> ../../docs_src/path_operation_advanced_configuration/tutorial007.py!}
```
////
@@ -176,7 +176,7 @@ In der folgenden Anwendung verwenden wir beispielsweise weder die integrierte Fu
//// tab | Pydantic v1
```Python hl_lines="17-22 24"
{!> ../../../docs_src/path_operation_advanced_configuration/tutorial007_pv1.py!}
{!> ../../docs_src/path_operation_advanced_configuration/tutorial007_pv1.py!}
```
////
@@ -196,7 +196,7 @@ Und dann parsen wir in unserem Code diesen YAML-Inhalt direkt und verwenden dann
//// tab | Pydantic v2
```Python hl_lines="26-33"
{!> ../../../docs_src/path_operation_advanced_configuration/tutorial007.py!}
{!> ../../docs_src/path_operation_advanced_configuration/tutorial007.py!}
```
////
@@ -204,7 +204,7 @@ Und dann parsen wir in unserem Code diesen YAML-Inhalt direkt und verwenden dann
//// tab | Pydantic v1
```Python hl_lines="26-33"
{!> ../../../docs_src/path_operation_advanced_configuration/tutorial007_pv1.py!}
{!> ../../docs_src/path_operation_advanced_configuration/tutorial007_pv1.py!}
```
////

View File

@@ -21,7 +21,7 @@ Sie können einen Parameter vom Typ `Response` in Ihrer *Pfadoperation-Funktion*
Anschließend können Sie den `status_code` in diesem *vorübergehenden* Response-Objekt festlegen.
```Python hl_lines="1 9 12"
{!../../../docs_src/response_change_status_code/tutorial001.py!}
{!../../docs_src/response_change_status_code/tutorial001.py!}
```
Und dann können Sie wie gewohnt jedes benötigte Objekt zurückgeben (ein `dict`, ein Datenbankmodell usw.).

View File

@@ -7,7 +7,7 @@ Sie können einen Parameter vom Typ `Response` in Ihrer *Pfadoperation-Funktion*
Und dann können Sie Cookies in diesem *vorübergehenden* Response-Objekt setzen.
```Python hl_lines="1 8-9"
{!../../../docs_src/response_cookies/tutorial002.py!}
{!../../docs_src/response_cookies/tutorial002.py!}
```
Anschließend können Sie wie gewohnt jedes gewünschte Objekt zurückgeben (ein `dict`, ein Datenbankmodell, usw.).
@@ -27,7 +27,7 @@ Dazu können Sie eine Response erstellen, wie unter [Eine Response direkt zurüc
Setzen Sie dann Cookies darin und geben Sie sie dann zurück:
```Python hl_lines="10-12"
{!../../../docs_src/response_cookies/tutorial001.py!}
{!../../docs_src/response_cookies/tutorial001.py!}
```
/// tip | "Tipp"

View File

@@ -35,7 +35,7 @@ Sie können beispielsweise kein Pydantic-Modell in eine `JSONResponse` einfügen
In diesen Fällen können Sie den `jsonable_encoder` verwenden, um Ihre Daten zu konvertieren, bevor Sie sie an eine Response übergeben:
```Python hl_lines="6-7 21-22"
{!../../../docs_src/response_directly/tutorial001.py!}
{!../../docs_src/response_directly/tutorial001.py!}
```
/// note | "Technische Details"
@@ -57,7 +57,7 @@ Nehmen wir an, Sie möchten eine <a href="https://en.wikipedia.org/wiki/XML" cla
Sie könnten Ihren XML-Inhalt als String in eine `Response` einfügen und sie zurückgeben:
```Python hl_lines="1 18"
{!../../../docs_src/response_directly/tutorial002.py!}
{!../../docs_src/response_directly/tutorial002.py!}
```
## Anmerkungen

View File

@@ -7,7 +7,7 @@ Sie können einen Parameter vom Typ `Response` in Ihrer *Pfadoperation-Funktion*
Und dann können Sie Header in diesem *vorübergehenden* Response-Objekt festlegen.
```Python hl_lines="1 7-8"
{!../../../docs_src/response_headers/tutorial002.py!}
{!../../docs_src/response_headers/tutorial002.py!}
```
Anschließend können Sie wie gewohnt jedes gewünschte Objekt zurückgeben (ein `dict`, ein Datenbankmodell, usw.).
@@ -25,7 +25,7 @@ Sie können auch Header hinzufügen, wenn Sie eine `Response` direkt zurückgebe
Erstellen Sie eine Response wie in [Eine Response direkt zurückgeben](response-directly.md){.internal-link target=_blank} beschrieben und übergeben Sie die Header als zusätzlichen Parameter:
```Python hl_lines="10-12"
{!../../../docs_src/response_headers/tutorial001.py!}
{!../../docs_src/response_headers/tutorial001.py!}
```
/// note | "Technische Details"

View File

@@ -23,7 +23,7 @@ Wenn Sie dann den Benutzernamen und das Passwort eingeben, sendet der Browser di
//// tab | Python 3.9+
```Python hl_lines="4 8 12"
{!> ../../../docs_src/security/tutorial006_an_py39.py!}
{!> ../../docs_src/security/tutorial006_an_py39.py!}
```
////
@@ -31,7 +31,7 @@ Wenn Sie dann den Benutzernamen und das Passwort eingeben, sendet der Browser di
//// tab | Python 3.8+
```Python hl_lines="2 7 11"
{!> ../../../docs_src/security/tutorial006_an.py!}
{!> ../../docs_src/security/tutorial006_an.py!}
```
////
@@ -45,7 +45,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="2 6 10"
{!> ../../../docs_src/security/tutorial006.py!}
{!> ../../docs_src/security/tutorial006.py!}
```
////
@@ -71,7 +71,7 @@ Dann können wir `secrets.compare_digest()` verwenden, um sicherzustellen, dass
//// tab | Python 3.9+
```Python hl_lines="1 12-24"
{!> ../../../docs_src/security/tutorial007_an_py39.py!}
{!> ../../docs_src/security/tutorial007_an_py39.py!}
```
////
@@ -79,7 +79,7 @@ Dann können wir `secrets.compare_digest()` verwenden, um sicherzustellen, dass
//// tab | Python 3.8+
```Python hl_lines="1 12-24"
{!> ../../../docs_src/security/tutorial007_an.py!}
{!> ../../docs_src/security/tutorial007_an.py!}
```
////
@@ -93,7 +93,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="1 11-21"
{!> ../../../docs_src/security/tutorial007.py!}
{!> ../../docs_src/security/tutorial007.py!}
```
////
@@ -163,7 +163,7 @@ Nachdem Sie festgestellt haben, dass die Anmeldeinformationen falsch sind, geben
//// tab | Python 3.9+
```Python hl_lines="26-30"
{!> ../../../docs_src/security/tutorial007_an_py39.py!}
{!> ../../docs_src/security/tutorial007_an_py39.py!}
```
////
@@ -171,7 +171,7 @@ Nachdem Sie festgestellt haben, dass die Anmeldeinformationen falsch sind, geben
//// tab | Python 3.8+
```Python hl_lines="26-30"
{!> ../../../docs_src/security/tutorial007_an.py!}
{!> ../../docs_src/security/tutorial007_an.py!}
```
////
@@ -185,7 +185,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="23-27"
{!> ../../../docs_src/security/tutorial007.py!}
{!> ../../docs_src/security/tutorial007.py!}
```
////

View File

@@ -65,7 +65,7 @@ Sehen wir uns zunächst kurz die Teile an, die sich gegenüber den Beispielen im
//// tab | Python 3.10+
```Python hl_lines="4 8 12 46 64 105 107-115 121-124 128-134 139 155"
{!> ../../../docs_src/security/tutorial005_an_py310.py!}
{!> ../../docs_src/security/tutorial005_an_py310.py!}
```
////
@@ -73,7 +73,7 @@ Sehen wir uns zunächst kurz die Teile an, die sich gegenüber den Beispielen im
//// tab | Python 3.9+
```Python hl_lines="2 4 8 12 46 64 105 107-115 121-124 128-134 139 155"
{!> ../../../docs_src/security/tutorial005_an_py39.py!}
{!> ../../docs_src/security/tutorial005_an_py39.py!}
```
////
@@ -81,7 +81,7 @@ Sehen wir uns zunächst kurz die Teile an, die sich gegenüber den Beispielen im
//// tab | Python 3.8+
```Python hl_lines="2 4 8 12 47 65 106 108-116 122-125 129-135 140 156"
{!> ../../../docs_src/security/tutorial005_an.py!}
{!> ../../docs_src/security/tutorial005_an.py!}
```
////
@@ -95,7 +95,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="3 7 11 45 63 104 106-114 120-123 127-133 138 154"
{!> ../../../docs_src/security/tutorial005_py310.py!}
{!> ../../docs_src/security/tutorial005_py310.py!}
```
////
@@ -109,7 +109,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="2 4 8 12 46 64 105 107-115 121-124 128-134 139 155"
{!> ../../../docs_src/security/tutorial005_py39.py!}
{!> ../../docs_src/security/tutorial005_py39.py!}
```
////
@@ -123,7 +123,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="2 4 8 12 46 64 105 107-115 121-124 128-134 139 155"
{!> ../../../docs_src/security/tutorial005.py!}
{!> ../../docs_src/security/tutorial005.py!}
```
////
@@ -139,7 +139,7 @@ Der `scopes`-Parameter erhält ein `dict` mit jedem Scope als Schlüssel und des
//// tab | Python 3.10+
```Python hl_lines="62-65"
{!> ../../../docs_src/security/tutorial005_an_py310.py!}
{!> ../../docs_src/security/tutorial005_an_py310.py!}
```
////
@@ -147,7 +147,7 @@ Der `scopes`-Parameter erhält ein `dict` mit jedem Scope als Schlüssel und des
//// tab | Python 3.9+
```Python hl_lines="62-65"
{!> ../../../docs_src/security/tutorial005_an_py39.py!}
{!> ../../docs_src/security/tutorial005_an_py39.py!}
```
////
@@ -155,7 +155,7 @@ Der `scopes`-Parameter erhält ein `dict` mit jedem Scope als Schlüssel und des
//// tab | Python 3.8+
```Python hl_lines="63-66"
{!> ../../../docs_src/security/tutorial005_an.py!}
{!> ../../docs_src/security/tutorial005_an.py!}
```
////
@@ -169,7 +169,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="61-64"
{!> ../../../docs_src/security/tutorial005_py310.py!}
{!> ../../docs_src/security/tutorial005_py310.py!}
```
////
@@ -183,7 +183,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="62-65"
{!> ../../../docs_src/security/tutorial005_py39.py!}
{!> ../../docs_src/security/tutorial005_py39.py!}
```
////
@@ -197,7 +197,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="62-65"
{!> ../../../docs_src/security/tutorial005.py!}
{!> ../../docs_src/security/tutorial005.py!}
```
////
@@ -229,7 +229,7 @@ Aus Sicherheitsgründen sollten Sie jedoch sicherstellen, dass Sie in Ihrer Anwe
//// tab | Python 3.10+
```Python hl_lines="155"
{!> ../../../docs_src/security/tutorial005_an_py310.py!}
{!> ../../docs_src/security/tutorial005_an_py310.py!}
```
////
@@ -237,7 +237,7 @@ Aus Sicherheitsgründen sollten Sie jedoch sicherstellen, dass Sie in Ihrer Anwe
//// tab | Python 3.9+
```Python hl_lines="155"
{!> ../../../docs_src/security/tutorial005_an_py39.py!}
{!> ../../docs_src/security/tutorial005_an_py39.py!}
```
////
@@ -245,7 +245,7 @@ Aus Sicherheitsgründen sollten Sie jedoch sicherstellen, dass Sie in Ihrer Anwe
//// tab | Python 3.8+
```Python hl_lines="156"
{!> ../../../docs_src/security/tutorial005_an.py!}
{!> ../../docs_src/security/tutorial005_an.py!}
```
////
@@ -259,7 +259,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="154"
{!> ../../../docs_src/security/tutorial005_py310.py!}
{!> ../../docs_src/security/tutorial005_py310.py!}
```
////
@@ -273,7 +273,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="155"
{!> ../../../docs_src/security/tutorial005_py39.py!}
{!> ../../docs_src/security/tutorial005_py39.py!}
```
////
@@ -287,7 +287,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="155"
{!> ../../../docs_src/security/tutorial005.py!}
{!> ../../docs_src/security/tutorial005.py!}
```
////
@@ -319,7 +319,7 @@ Wir tun dies hier, um zu demonstrieren, wie **FastAPI** auf verschiedenen Ebenen
//// tab | Python 3.10+
```Python hl_lines="4 139 170"
{!> ../../../docs_src/security/tutorial005_an_py310.py!}
{!> ../../docs_src/security/tutorial005_an_py310.py!}
```
////
@@ -327,7 +327,7 @@ Wir tun dies hier, um zu demonstrieren, wie **FastAPI** auf verschiedenen Ebenen
//// tab | Python 3.9+
```Python hl_lines="4 139 170"
{!> ../../../docs_src/security/tutorial005_an_py39.py!}
{!> ../../docs_src/security/tutorial005_an_py39.py!}
```
////
@@ -335,7 +335,7 @@ Wir tun dies hier, um zu demonstrieren, wie **FastAPI** auf verschiedenen Ebenen
//// tab | Python 3.8+
```Python hl_lines="4 140 171"
{!> ../../../docs_src/security/tutorial005_an.py!}
{!> ../../docs_src/security/tutorial005_an.py!}
```
////
@@ -349,7 +349,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="3 138 167"
{!> ../../../docs_src/security/tutorial005_py310.py!}
{!> ../../docs_src/security/tutorial005_py310.py!}
```
////
@@ -363,7 +363,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="4 139 168"
{!> ../../../docs_src/security/tutorial005_py39.py!}
{!> ../../docs_src/security/tutorial005_py39.py!}
```
////
@@ -377,7 +377,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="4 139 168"
{!> ../../../docs_src/security/tutorial005.py!}
{!> ../../docs_src/security/tutorial005.py!}
```
////
@@ -409,7 +409,7 @@ Diese `SecurityScopes`-Klasse ähnelt `Request` (`Request` wurde verwendet, um d
//// tab | Python 3.10+
```Python hl_lines="8 105"
{!> ../../../docs_src/security/tutorial005_an_py310.py!}
{!> ../../docs_src/security/tutorial005_an_py310.py!}
```
////
@@ -417,7 +417,7 @@ Diese `SecurityScopes`-Klasse ähnelt `Request` (`Request` wurde verwendet, um d
//// tab | Python 3.9+
```Python hl_lines="8 105"
{!> ../../../docs_src/security/tutorial005_an_py39.py!}
{!> ../../docs_src/security/tutorial005_an_py39.py!}
```
////
@@ -425,7 +425,7 @@ Diese `SecurityScopes`-Klasse ähnelt `Request` (`Request` wurde verwendet, um d
//// tab | Python 3.8+
```Python hl_lines="8 106"
{!> ../../../docs_src/security/tutorial005_an.py!}
{!> ../../docs_src/security/tutorial005_an.py!}
```
////
@@ -439,7 +439,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7 104"
{!> ../../../docs_src/security/tutorial005_py310.py!}
{!> ../../docs_src/security/tutorial005_py310.py!}
```
////
@@ -453,7 +453,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="8 105"
{!> ../../../docs_src/security/tutorial005_py39.py!}
{!> ../../docs_src/security/tutorial005_py39.py!}
```
////
@@ -467,7 +467,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="8 105"
{!> ../../../docs_src/security/tutorial005.py!}
{!> ../../docs_src/security/tutorial005.py!}
```
////
@@ -487,7 +487,7 @@ In diese Exception fügen wir (falls vorhanden) die erforderlichen Scopes als du
//// tab | Python 3.10+
```Python hl_lines="105 107-115"
{!> ../../../docs_src/security/tutorial005_an_py310.py!}
{!> ../../docs_src/security/tutorial005_an_py310.py!}
```
////
@@ -495,7 +495,7 @@ In diese Exception fügen wir (falls vorhanden) die erforderlichen Scopes als du
//// tab | Python 3.9+
```Python hl_lines="105 107-115"
{!> ../../../docs_src/security/tutorial005_an_py39.py!}
{!> ../../docs_src/security/tutorial005_an_py39.py!}
```
////
@@ -503,7 +503,7 @@ In diese Exception fügen wir (falls vorhanden) die erforderlichen Scopes als du
//// tab | Python 3.8+
```Python hl_lines="106 108-116"
{!> ../../../docs_src/security/tutorial005_an.py!}
{!> ../../docs_src/security/tutorial005_an.py!}
```
////
@@ -517,7 +517,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="104 106-114"
{!> ../../../docs_src/security/tutorial005_py310.py!}
{!> ../../docs_src/security/tutorial005_py310.py!}
```
////
@@ -531,7 +531,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="105 107-115"
{!> ../../../docs_src/security/tutorial005_py39.py!}
{!> ../../docs_src/security/tutorial005_py39.py!}
```
////
@@ -545,7 +545,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="105 107-115"
{!> ../../../docs_src/security/tutorial005.py!}
{!> ../../docs_src/security/tutorial005.py!}
```
////
@@ -567,7 +567,7 @@ Wir verifizieren auch, dass wir einen Benutzer mit diesem Benutzernamen haben, u
//// tab | Python 3.10+
```Python hl_lines="46 116-127"
{!> ../../../docs_src/security/tutorial005_an_py310.py!}
{!> ../../docs_src/security/tutorial005_an_py310.py!}
```
////
@@ -575,7 +575,7 @@ Wir verifizieren auch, dass wir einen Benutzer mit diesem Benutzernamen haben, u
//// tab | Python 3.9+
```Python hl_lines="46 116-127"
{!> ../../../docs_src/security/tutorial005_an_py39.py!}
{!> ../../docs_src/security/tutorial005_an_py39.py!}
```
////
@@ -583,7 +583,7 @@ Wir verifizieren auch, dass wir einen Benutzer mit diesem Benutzernamen haben, u
//// tab | Python 3.8+
```Python hl_lines="47 117-128"
{!> ../../../docs_src/security/tutorial005_an.py!}
{!> ../../docs_src/security/tutorial005_an.py!}
```
////
@@ -597,7 +597,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="45 115-126"
{!> ../../../docs_src/security/tutorial005_py310.py!}
{!> ../../docs_src/security/tutorial005_py310.py!}
```
////
@@ -611,7 +611,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="46 116-127"
{!> ../../../docs_src/security/tutorial005_py39.py!}
{!> ../../docs_src/security/tutorial005_py39.py!}
```
////
@@ -625,7 +625,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="46 116-127"
{!> ../../../docs_src/security/tutorial005.py!}
{!> ../../docs_src/security/tutorial005.py!}
```
////
@@ -639,7 +639,7 @@ Hierzu verwenden wir `security_scopes.scopes`, das eine `list`e mit allen diesen
//// tab | Python 3.10+
```Python hl_lines="128-134"
{!> ../../../docs_src/security/tutorial005_an_py310.py!}
{!> ../../docs_src/security/tutorial005_an_py310.py!}
```
////
@@ -647,7 +647,7 @@ Hierzu verwenden wir `security_scopes.scopes`, das eine `list`e mit allen diesen
//// tab | Python 3.9+
```Python hl_lines="128-134"
{!> ../../../docs_src/security/tutorial005_an_py39.py!}
{!> ../../docs_src/security/tutorial005_an_py39.py!}
```
////
@@ -655,7 +655,7 @@ Hierzu verwenden wir `security_scopes.scopes`, das eine `list`e mit allen diesen
//// tab | Python 3.8+
```Python hl_lines="129-135"
{!> ../../../docs_src/security/tutorial005_an.py!}
{!> ../../docs_src/security/tutorial005_an.py!}
```
////
@@ -669,7 +669,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="127-133"
{!> ../../../docs_src/security/tutorial005_py310.py!}
{!> ../../docs_src/security/tutorial005_py310.py!}
```
////
@@ -683,7 +683,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="128-134"
{!> ../../../docs_src/security/tutorial005_py39.py!}
{!> ../../docs_src/security/tutorial005_py39.py!}
```
////
@@ -697,7 +697,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="128-134"
{!> ../../../docs_src/security/tutorial005.py!}
{!> ../../docs_src/security/tutorial005.py!}
```
////

View File

@@ -181,7 +181,7 @@ Sie können dieselben Validierungs-Funktionen und -Tools verwenden, die Sie für
//// tab | Pydantic v2
```Python hl_lines="2 5-8 11"
{!> ../../../docs_src/settings/tutorial001.py!}
{!> ../../docs_src/settings/tutorial001.py!}
```
////
@@ -195,7 +195,7 @@ In Pydantic v1 würden Sie `BaseSettings` direkt von `pydantic` statt von `pydan
///
```Python hl_lines="2 5-8 11"
{!> ../../../docs_src/settings/tutorial001_pv1.py!}
{!> ../../docs_src/settings/tutorial001_pv1.py!}
```
////
@@ -215,7 +215,7 @@ Als Nächstes werden die Daten konvertiert und validiert. Wenn Sie also dieses `
Dann können Sie das neue `settings`-Objekt in Ihrer Anwendung verwenden:
```Python hl_lines="18-20"
{!../../../docs_src/settings/tutorial001.py!}
{!../../docs_src/settings/tutorial001.py!}
```
### Den Server ausführen
@@ -251,13 +251,13 @@ Sie könnten diese Einstellungen in eine andere Moduldatei einfügen, wie Sie in
Sie könnten beispielsweise eine Datei `config.py` haben mit:
```Python
{!../../../docs_src/settings/app01/config.py!}
{!../../docs_src/settings/app01/config.py!}
```
Und dann verwenden Sie diese in einer Datei `main.py`:
```Python hl_lines="3 11-13"
{!../../../docs_src/settings/app01/main.py!}
{!../../docs_src/settings/app01/main.py!}
```
/// tip | "Tipp"
@@ -277,7 +277,7 @@ Dies könnte besonders beim Testen nützlich sein, da es sehr einfach ist, eine
Ausgehend vom vorherigen Beispiel könnte Ihre Datei `config.py` so aussehen:
```Python hl_lines="10"
{!../../../docs_src/settings/app02/config.py!}
{!../../docs_src/settings/app02/config.py!}
```
Beachten Sie, dass wir jetzt keine Standardinstanz `settings = Settings()` erstellen.
@@ -289,7 +289,7 @@ Jetzt erstellen wir eine Abhängigkeit, die ein neues `config.Settings()` zurüc
//// tab | Python 3.9+
```Python hl_lines="6 12-13"
{!> ../../../docs_src/settings/app02_an_py39/main.py!}
{!> ../../docs_src/settings/app02_an_py39/main.py!}
```
////
@@ -297,7 +297,7 @@ Jetzt erstellen wir eine Abhängigkeit, die ein neues `config.Settings()` zurüc
//// tab | Python 3.8+
```Python hl_lines="6 12-13"
{!> ../../../docs_src/settings/app02_an/main.py!}
{!> ../../docs_src/settings/app02_an/main.py!}
```
////
@@ -311,7 +311,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="5 11-12"
{!> ../../../docs_src/settings/app02/main.py!}
{!> ../../docs_src/settings/app02/main.py!}
```
////
@@ -329,7 +329,7 @@ Und dann können wir das von der *Pfadoperation-Funktion* als Abhängigkeit einf
//// tab | Python 3.9+
```Python hl_lines="17 19-21"
{!> ../../../docs_src/settings/app02_an_py39/main.py!}
{!> ../../docs_src/settings/app02_an_py39/main.py!}
```
////
@@ -337,7 +337,7 @@ Und dann können wir das von der *Pfadoperation-Funktion* als Abhängigkeit einf
//// tab | Python 3.8+
```Python hl_lines="17 19-21"
{!> ../../../docs_src/settings/app02_an/main.py!}
{!> ../../docs_src/settings/app02_an/main.py!}
```
////
@@ -351,7 +351,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="16 18-20"
{!> ../../../docs_src/settings/app02/main.py!}
{!> ../../docs_src/settings/app02/main.py!}
```
////
@@ -361,7 +361,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
Dann wäre es sehr einfach, beim Testen ein anderes Einstellungsobjekt bereitzustellen, indem man eine Abhängigkeitsüberschreibung für `get_settings` erstellt:
```Python hl_lines="9-10 13 21"
{!../../../docs_src/settings/app02/test_main.py!}
{!../../docs_src/settings/app02/test_main.py!}
```
Bei der Abhängigkeitsüberschreibung legen wir einen neuen Wert für `admin_email` fest, wenn wir das neue `Settings`-Objekt erstellen, und geben dann dieses neue Objekt zurück.
@@ -406,7 +406,7 @@ Und dann aktualisieren Sie Ihre `config.py` mit:
//// tab | Pydantic v2
```Python hl_lines="9"
{!> ../../../docs_src/settings/app03_an/config.py!}
{!> ../../docs_src/settings/app03_an/config.py!}
```
/// tip | "Tipp"
@@ -420,7 +420,7 @@ Das Attribut `model_config` wird nur für die Pydantic-Konfiguration verwendet.
//// tab | Pydantic v1
```Python hl_lines="9-10"
{!> ../../../docs_src/settings/app03_an/config_pv1.py!}
{!> ../../docs_src/settings/app03_an/config_pv1.py!}
```
/// tip | "Tipp"
@@ -465,7 +465,7 @@ Da wir jedoch den `@lru_cache`-Dekorator oben verwenden, wird das `Settings`-Obj
//// tab | Python 3.9+
```Python hl_lines="1 11"
{!> ../../../docs_src/settings/app03_an_py39/main.py!}
{!> ../../docs_src/settings/app03_an_py39/main.py!}
```
////
@@ -473,7 +473,7 @@ Da wir jedoch den `@lru_cache`-Dekorator oben verwenden, wird das `Settings`-Obj
//// tab | Python 3.8+
```Python hl_lines="1 11"
{!> ../../../docs_src/settings/app03_an/main.py!}
{!> ../../docs_src/settings/app03_an/main.py!}
```
////
@@ -487,7 +487,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="1 10"
{!> ../../../docs_src/settings/app03/main.py!}
{!> ../../docs_src/settings/app03/main.py!}
```
////

View File

@@ -11,7 +11,7 @@ Wenn Sie zwei unabhängige FastAPI-Anwendungen mit deren eigenen unabhängigen O
Erstellen Sie zunächst die Hauptanwendung **FastAPI** und deren *Pfadoperationen*:
```Python hl_lines="3 6-8"
{!../../../docs_src/sub_applications/tutorial001.py!}
{!../../docs_src/sub_applications/tutorial001.py!}
```
### Unteranwendung
@@ -21,7 +21,7 @@ Erstellen Sie dann Ihre Unteranwendung und deren *Pfadoperationen*.
Diese Unteranwendung ist nur eine weitere Standard-FastAPI-Anwendung, aber diese wird „gemountet“:
```Python hl_lines="11 14-16"
{!../../../docs_src/sub_applications/tutorial001.py!}
{!../../docs_src/sub_applications/tutorial001.py!}
```
### Die Unteranwendung mounten
@@ -31,7 +31,7 @@ Mounten Sie in Ihrer Top-Level-Anwendung `app` die Unteranwendung `subapi`.
In diesem Fall wird sie im Pfad `/subapi` gemountet:
```Python hl_lines="11 19"
{!../../../docs_src/sub_applications/tutorial001.py!}
{!../../docs_src/sub_applications/tutorial001.py!}
```
### Es in der automatischen API-Dokumentation betrachten

View File

@@ -28,7 +28,7 @@ $ pip install jinja2
* Verwenden Sie die von Ihnen erstellten `templates`, um eine `TemplateResponse` zu rendern und zurückzugeben, übergeben Sie den Namen des Templates, das Requestobjekt und ein „Kontext“-Dictionary mit Schlüssel-Wert-Paaren, die innerhalb des Jinja2-Templates verwendet werden sollen.
```Python hl_lines="4 11 15-18"
{!../../../docs_src/templates/tutorial001.py!}
{!../../docs_src/templates/tutorial001.py!}
```
/// note | "Hinweis"
@@ -58,7 +58,7 @@ Sie können auch `from starlette.templating import Jinja2Templates` verwenden.
Dann können Sie unter `templates/item.html` ein Template erstellen, mit z. B. folgendem Inhalt:
```jinja hl_lines="7"
{!../../../docs_src/templates/templates/item.html!}
{!../../docs_src/templates/templates/item.html!}
```
### Template-Kontextwerte
@@ -112,13 +112,13 @@ Mit beispielsweise der ID `42` würde dies Folgendes ergeben:
Sie können `url_for()` innerhalb des Templates auch beispielsweise mit den `StaticFiles` verwenden, die Sie mit `name="static"` gemountet haben.
```jinja hl_lines="4"
{!../../../docs_src/templates/templates/item.html!}
{!../../docs_src/templates/templates/item.html!}
```
In diesem Beispiel würde das zu einer CSS-Datei unter `static/styles.css` verlinken, mit folgendem Inhalt:
```CSS hl_lines="4"
{!../../../docs_src/templates/static/styles.css!}
{!../../docs_src/templates/static/styles.css!}
```
Und da Sie `StaticFiles` verwenden, wird diese CSS-Datei automatisch von Ihrer **FastAPI**-Anwendung unter der URL `/static/styles.css` bereitgestellt.

View File

@@ -31,7 +31,7 @@ Und dann ruft **FastAPI** diese Überschreibung anstelle der ursprünglichen Abh
//// tab | Python 3.10+
```Python hl_lines="26-27 30"
{!> ../../../docs_src/dependency_testing/tutorial001_an_py310.py!}
{!> ../../docs_src/dependency_testing/tutorial001_an_py310.py!}
```
////
@@ -39,7 +39,7 @@ Und dann ruft **FastAPI** diese Überschreibung anstelle der ursprünglichen Abh
//// tab | Python 3.9+
```Python hl_lines="28-29 32"
{!> ../../../docs_src/dependency_testing/tutorial001_an_py39.py!}
{!> ../../docs_src/dependency_testing/tutorial001_an_py39.py!}
```
////
@@ -47,7 +47,7 @@ Und dann ruft **FastAPI** diese Überschreibung anstelle der ursprünglichen Abh
//// tab | Python 3.8+
```Python hl_lines="29-30 33"
{!> ../../../docs_src/dependency_testing/tutorial001_an.py!}
{!> ../../docs_src/dependency_testing/tutorial001_an.py!}
```
////
@@ -61,7 +61,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="24-25 28"
{!> ../../../docs_src/dependency_testing/tutorial001_py310.py!}
{!> ../../docs_src/dependency_testing/tutorial001_py310.py!}
```
////
@@ -75,7 +75,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="28-29 32"
{!> ../../../docs_src/dependency_testing/tutorial001.py!}
{!> ../../docs_src/dependency_testing/tutorial001.py!}
```
////

View File

@@ -3,5 +3,5 @@
Wenn Sie in Ihren Tests Ihre Event-Handler (`startup` und `shutdown`) ausführen wollen, können Sie den `TestClient` mit einer `with`-Anweisung verwenden:
```Python hl_lines="9-12 20-24"
{!../../../docs_src/app_testing/tutorial003.py!}
{!../../docs_src/app_testing/tutorial003.py!}
```

View File

@@ -5,7 +5,7 @@ Sie können den schon bekannten `TestClient` zum Testen von WebSockets verwenden
Dazu verwenden Sie den `TestClient` in einer `with`-Anweisung, eine Verbindung zum WebSocket herstellend:
```Python hl_lines="27-31"
{!../../../docs_src/app_testing/tutorial002.py!}
{!../../docs_src/app_testing/tutorial002.py!}
```
/// note | "Hinweis"

View File

@@ -30,7 +30,7 @@ Angenommen, Sie möchten auf die IP-Adresse/den Host des Clients in Ihrer *Pfado
Dazu müssen Sie direkt auf den Request zugreifen.
```Python hl_lines="1 7-8"
{!../../../docs_src/using_request_directly/tutorial001.py!}
{!../../docs_src/using_request_directly/tutorial001.py!}
```
Durch die Deklaration eines *Pfadoperation-Funktionsparameters*, dessen Typ der `Request` ist, weiß **FastAPI**, dass es den `Request` diesem Parameter übergeben soll.

View File

@@ -39,7 +39,7 @@ In der Produktion hätten Sie eine der oben genannten Optionen.
Aber es ist die einfachste Möglichkeit, sich auf die Serverseite von WebSockets zu konzentrieren und ein funktionierendes Beispiel zu haben:
```Python hl_lines="2 6-38 41-43"
{!../../../docs_src/websockets/tutorial001.py!}
{!../../docs_src/websockets/tutorial001.py!}
```
## Einen `websocket` erstellen
@@ -47,7 +47,7 @@ Aber es ist die einfachste Möglichkeit, sich auf die Serverseite von WebSockets
Erstellen Sie in Ihrer **FastAPI**-Anwendung einen `websocket`:
```Python hl_lines="1 46-47"
{!../../../docs_src/websockets/tutorial001.py!}
{!../../docs_src/websockets/tutorial001.py!}
```
/// note | "Technische Details"
@@ -63,7 +63,7 @@ Sie können auch `from starlette.websockets import WebSocket` verwenden.
In Ihrer WebSocket-Route können Sie Nachrichten `await`en und Nachrichten senden.
```Python hl_lines="48-52"
{!../../../docs_src/websockets/tutorial001.py!}
{!../../docs_src/websockets/tutorial001.py!}
```
Sie können Binär-, Text- und JSON-Daten empfangen und senden.
@@ -118,7 +118,7 @@ Diese funktionieren auf die gleiche Weise wie für andere FastAPI-Endpunkte/*Pfa
//// tab | Python 3.10+
```Python hl_lines="68-69 82"
{!> ../../../docs_src/websockets/tutorial002_an_py310.py!}
{!> ../../docs_src/websockets/tutorial002_an_py310.py!}
```
////
@@ -126,7 +126,7 @@ Diese funktionieren auf die gleiche Weise wie für andere FastAPI-Endpunkte/*Pfa
//// tab | Python 3.9+
```Python hl_lines="68-69 82"
{!> ../../../docs_src/websockets/tutorial002_an_py39.py!}
{!> ../../docs_src/websockets/tutorial002_an_py39.py!}
```
////
@@ -134,7 +134,7 @@ Diese funktionieren auf die gleiche Weise wie für andere FastAPI-Endpunkte/*Pfa
//// tab | Python 3.8+
```Python hl_lines="69-70 83"
{!> ../../../docs_src/websockets/tutorial002_an.py!}
{!> ../../docs_src/websockets/tutorial002_an.py!}
```
////
@@ -148,7 +148,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="66-67 79"
{!> ../../../docs_src/websockets/tutorial002_py310.py!}
{!> ../../docs_src/websockets/tutorial002_py310.py!}
```
////
@@ -162,7 +162,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="68-69 81"
{!> ../../../docs_src/websockets/tutorial002.py!}
{!> ../../docs_src/websockets/tutorial002.py!}
```
////
@@ -213,7 +213,7 @@ Wenn eine WebSocket-Verbindung geschlossen wird, löst `await websocket.receive_
//// tab | Python 3.9+
```Python hl_lines="79-81"
{!> ../../../docs_src/websockets/tutorial003_py39.py!}
{!> ../../docs_src/websockets/tutorial003_py39.py!}
```
////
@@ -221,7 +221,7 @@ Wenn eine WebSocket-Verbindung geschlossen wird, löst `await websocket.receive_
//// tab | Python 3.8+
```Python hl_lines="81-83"
{!> ../../../docs_src/websockets/tutorial003.py!}
{!> ../../docs_src/websockets/tutorial003.py!}
```
////

View File

@@ -13,7 +13,7 @@ Wrappen Sie dann die WSGI-Anwendung (z. B. Flask) mit der Middleware.
Und dann mounten Sie das auf einem Pfad.
```Python hl_lines="2-3 23"
{!../../../docs_src/wsgi/tutorial001.py!}
{!../../docs_src/wsgi/tutorial001.py!}
```
## Es ansehen

View File

@@ -321,7 +321,7 @@ Das hat tatsächlich dazu geführt, dass Teile von Pydantic aktualisiert wurden,
///
### <a href="https://www.hug.rest/" class="external-link" target="_blank">Hug</a>
### <a href="https://github.com/hugapi/hug" class="external-link" target="_blank">Hug</a>
Hug war eines der ersten Frameworks, welches die Deklaration von API-Parametertypen mithilfe von Python-Typhinweisen implementierte. Das war eine großartige Idee, die andere Tools dazu inspirierte, dasselbe zu tun.

View File

@@ -30,7 +30,7 @@ Sie können problemlos dieselben Pydantic-Einstellungen verwenden, um Ihre gener
Zum Beispiel:
```Python hl_lines="6 11"
{!../../../docs_src/conditional_openapi/tutorial001.py!}
{!../../docs_src/conditional_openapi/tutorial001.py!}
```
Hier deklarieren wir die Einstellung `openapi_url` mit dem gleichen Defaultwert `"/openapi.json"`.

View File

@@ -1,6 +1,6 @@
# Swagger-Oberfläche konfigurieren
Sie können einige zusätzliche <a href="https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration" class="external-link" target="_blank">Parameter der Swagger-Oberfläche</a> konfigurieren.
Sie können einige zusätzliche <a href="https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/" class="external-link" target="_blank">Parameter der Swagger-Oberfläche</a> konfigurieren.
Um diese zu konfigurieren, übergeben Sie das Argument `swagger_ui_parameters` beim Erstellen des `FastAPI()`-App-Objekts oder an die Funktion `get_swagger_ui_html()`.
@@ -19,7 +19,7 @@ Ohne Änderung der Einstellungen ist die Syntaxhervorhebung standardmäßig akti
Sie können sie jedoch deaktivieren, indem Sie `syntaxHighlight` auf `False` setzen:
```Python hl_lines="3"
{!../../../docs_src/configure_swagger_ui/tutorial001.py!}
{!../../docs_src/configure_swagger_ui/tutorial001.py!}
```
... und dann zeigt die Swagger-Oberfläche die Syntaxhervorhebung nicht mehr an:
@@ -31,7 +31,7 @@ Sie können sie jedoch deaktivieren, indem Sie `syntaxHighlight` auf `False` set
Auf die gleiche Weise könnten Sie das Theme der Syntaxhervorhebung mit dem Schlüssel `syntaxHighlight.theme` festlegen (beachten Sie, dass er einen Punkt in der Mitte hat):
```Python hl_lines="3"
{!../../../docs_src/configure_swagger_ui/tutorial002.py!}
{!../../docs_src/configure_swagger_ui/tutorial002.py!}
```
Obige Konfiguration würde das Theme für die Farbe der Syntaxhervorhebung ändern:
@@ -45,7 +45,7 @@ FastAPI enthält einige Defaultkonfigurationsparameter, die für die meisten Anw
Es umfasst die folgenden Defaultkonfigurationen:
```Python
{!../../../fastapi/openapi/docs.py[ln:7-23]!}
{!../../fastapi/openapi/docs.py[ln:7-23]!}
```
Sie können jede davon überschreiben, indem Sie im Argument `swagger_ui_parameters` einen anderen Wert festlegen.
@@ -53,12 +53,12 @@ Sie können jede davon überschreiben, indem Sie im Argument `swagger_ui_paramet
Um beispielsweise `deepLinking` zu deaktivieren, könnten Sie folgende Einstellungen an `swagger_ui_parameters` übergeben:
```Python hl_lines="3"
{!../../../docs_src/configure_swagger_ui/tutorial003.py!}
{!../../docs_src/configure_swagger_ui/tutorial003.py!}
```
## Andere Parameter der Swagger-Oberfläche
Um alle anderen möglichen Konfigurationen zu sehen, die Sie verwenden können, lesen Sie die offizielle <a href="https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration" class="external-link" target="_blank">Dokumentation für die Parameter der Swagger-Oberfläche</a>.
Um alle anderen möglichen Konfigurationen zu sehen, die Sie verwenden können, lesen Sie die offizielle <a href="https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/" class="external-link" target="_blank">Dokumentation für die Parameter der Swagger-Oberfläche</a>.
## JavaScript-basierte Einstellungen

View File

@@ -19,7 +19,7 @@ Der erste Schritt besteht darin, die automatischen Dokumentationen zu deaktivier
Um diese zu deaktivieren, setzen Sie deren URLs beim Erstellen Ihrer `FastAPI`-App auf `None`:
```Python hl_lines="8"
{!../../../docs_src/custom_docs_ui/tutorial001.py!}
{!../../docs_src/custom_docs_ui/tutorial001.py!}
```
### Die benutzerdefinierten Dokumentationen hinzufügen
@@ -37,7 +37,7 @@ Sie können die internen Funktionen von FastAPI wiederverwenden, um die HTML-Sei
Und genau so für ReDoc ...
```Python hl_lines="2-6 11-19 22-24 27-33"
{!../../../docs_src/custom_docs_ui/tutorial001.py!}
{!../../docs_src/custom_docs_ui/tutorial001.py!}
```
/// tip | "Tipp"
@@ -55,7 +55,7 @@ Swagger UI erledigt das hinter den Kulissen für Sie, benötigt aber diesen „U
Um nun testen zu können, ob alles funktioniert, erstellen Sie eine *Pfadoperation*:
```Python hl_lines="36-38"
{!../../../docs_src/custom_docs_ui/tutorial001.py!}
{!../../docs_src/custom_docs_ui/tutorial001.py!}
```
### Es ausprobieren
@@ -125,7 +125,7 @@ Danach könnte Ihre Dateistruktur wie folgt aussehen:
* „Mounten“ Sie eine `StaticFiles()`-Instanz in einem bestimmten Pfad.
```Python hl_lines="7 11"
{!../../../docs_src/custom_docs_ui/tutorial002.py!}
{!../../docs_src/custom_docs_ui/tutorial002.py!}
```
### Die statischen Dateien testen
@@ -159,7 +159,7 @@ Wie bei der Verwendung eines benutzerdefinierten CDN besteht der erste Schritt d
Um diese zu deaktivieren, setzen Sie deren URLs beim Erstellen Ihrer `FastAPI`-App auf `None`:
```Python hl_lines="9"
{!../../../docs_src/custom_docs_ui/tutorial002.py!}
{!../../docs_src/custom_docs_ui/tutorial002.py!}
```
### Die benutzerdefinierten Dokumentationen, mit statischen Dateien, hinzufügen
@@ -177,7 +177,7 @@ Auch hier können Sie die internen Funktionen von FastAPI wiederverwenden, um di
Und genau so für ReDoc ...
```Python hl_lines="2-6 14-22 25-27 30-36"
{!../../../docs_src/custom_docs_ui/tutorial002.py!}
{!../../docs_src/custom_docs_ui/tutorial002.py!}
```
/// tip | "Tipp"
@@ -195,7 +195,7 @@ Swagger UI erledigt das hinter den Kulissen für Sie, benötigt aber diesen „U
Um nun testen zu können, ob alles funktioniert, erstellen Sie eine *Pfadoperation*:
```Python hl_lines="39-41"
{!../../../docs_src/custom_docs_ui/tutorial002.py!}
{!../../docs_src/custom_docs_ui/tutorial002.py!}
```
### Benutzeroberfläche, mit statischen Dateien, testen

View File

@@ -43,7 +43,7 @@ Wenn der Header kein `gzip` enthält, wird nicht versucht, den Body zu dekomprim
Auf diese Weise kann dieselbe Routenklasse gzip-komprimierte oder unkomprimierte Requests verarbeiten.
```Python hl_lines="8-15"
{!../../../docs_src/custom_request_and_route/tutorial001.py!}
{!../../docs_src/custom_request_and_route/tutorial001.py!}
```
### Eine benutzerdefinierte `GzipRoute`-Klasse erstellen
@@ -57,7 +57,7 @@ Diese Methode gibt eine Funktion zurück. Und diese Funktion empfängt einen Req
Hier verwenden wir sie, um aus dem ursprünglichen Request einen `GzipRequest` zu erstellen.
```Python hl_lines="18-26"
{!../../../docs_src/custom_request_and_route/tutorial001.py!}
{!../../docs_src/custom_request_and_route/tutorial001.py!}
```
/// note | "Technische Details"
@@ -97,13 +97,13 @@ Wir können denselben Ansatz auch verwenden, um in einem Exceptionhandler auf de
Alles, was wir tun müssen, ist, den Request innerhalb eines `try`/`except`-Blocks zu handhaben:
```Python hl_lines="13 15"
{!../../../docs_src/custom_request_and_route/tutorial002.py!}
{!../../docs_src/custom_request_and_route/tutorial002.py!}
```
Wenn eine Exception auftritt, befindet sich die `Request`-Instanz weiterhin im Gültigkeitsbereich, sodass wir den Requestbody lesen und bei der Fehlerbehandlung verwenden können:
```Python hl_lines="16-18"
{!../../../docs_src/custom_request_and_route/tutorial002.py!}
{!../../docs_src/custom_request_and_route/tutorial002.py!}
```
## Benutzerdefinierte `APIRoute`-Klasse in einem Router
@@ -111,11 +111,11 @@ Wenn eine Exception auftritt, befindet sich die `Request`-Instanz weiterhin im G
Sie können auch den Parameter `route_class` eines `APIRouter` festlegen:
```Python hl_lines="26"
{!../../../docs_src/custom_request_and_route/tutorial003.py!}
{!../../docs_src/custom_request_and_route/tutorial003.py!}
```
In diesem Beispiel verwenden die *Pfadoperationen* unter dem `router` die benutzerdefinierte `TimedRoute`-Klasse und haben in der Response einen zusätzlichen `X-Response-Time`-Header mit der Zeit, die zum Generieren der Response benötigt wurde:
```Python hl_lines="13-20"
{!../../../docs_src/custom_request_and_route/tutorial003.py!}
{!../../docs_src/custom_request_and_route/tutorial003.py!}
```

View File

@@ -44,7 +44,7 @@ Fügen wir beispielsweise <a href="https://github.com/Rebilly/ReDoc/blob/master/
Schreiben Sie zunächst wie gewohnt Ihre ganze **FastAPI**-Anwendung:
```Python hl_lines="1 4 7-9"
{!../../../docs_src/extending_openapi/tutorial001.py!}
{!../../docs_src/extending_openapi/tutorial001.py!}
```
### Das OpenAPI-Schema generieren
@@ -52,7 +52,7 @@ Schreiben Sie zunächst wie gewohnt Ihre ganze **FastAPI**-Anwendung:
Verwenden Sie dann dieselbe Hilfsfunktion, um das OpenAPI-Schema innerhalb einer `custom_openapi()`-Funktion zu generieren:
```Python hl_lines="2 15-21"
{!../../../docs_src/extending_openapi/tutorial001.py!}
{!../../docs_src/extending_openapi/tutorial001.py!}
```
### Das OpenAPI-Schema ändern
@@ -60,7 +60,7 @@ Verwenden Sie dann dieselbe Hilfsfunktion, um das OpenAPI-Schema innerhalb einer
Jetzt können Sie die ReDoc-Erweiterung hinzufügen und dem `info`-„Objekt“ im OpenAPI-Schema ein benutzerdefiniertes `x-logo` hinzufügen:
```Python hl_lines="22-24"
{!../../../docs_src/extending_openapi/tutorial001.py!}
{!../../docs_src/extending_openapi/tutorial001.py!}
```
### Zwischenspeichern des OpenAPI-Schemas
@@ -72,7 +72,7 @@ Auf diese Weise muss Ihre Anwendung das Schema nicht jedes Mal generieren, wenn
Es wird nur einmal generiert und dann wird dasselbe zwischengespeicherte Schema für die nächsten Requests verwendet.
```Python hl_lines="13-14 25-26"
{!../../../docs_src/extending_openapi/tutorial001.py!}
{!../../docs_src/extending_openapi/tutorial001.py!}
```
### Die Methode überschreiben
@@ -80,7 +80,7 @@ Es wird nur einmal generiert und dann wird dasselbe zwischengespeicherte Schema
Jetzt können Sie die Methode `.openapi()` durch Ihre neue Funktion ersetzen.
```Python hl_lines="29"
{!../../../docs_src/extending_openapi/tutorial001.py!}
{!../../docs_src/extending_openapi/tutorial001.py!}
```
### Testen

View File

@@ -36,7 +36,7 @@ Abhängig von Ihrem Anwendungsfall bevorzugen Sie vielleicht eine andere Bibliot
Hier ist eine kleine Vorschau, wie Sie Strawberry mit FastAPI integrieren können:
```Python hl_lines="3 22 25-26"
{!../../../docs_src/graphql/tutorial001.py!}
{!../../docs_src/graphql/tutorial001.py!}
```
Weitere Informationen zu Strawberry finden Sie in der <a href="https://strawberry.rocks/" class="external-link" target="_blank">Strawberry-Dokumentation</a>.

View File

@@ -13,7 +13,7 @@ Nehmen wir an, Sie haben ein Pydantic-Modell mit Defaultwerten wie dieses:
//// tab | Python 3.10+
```Python hl_lines="7"
{!> ../../../docs_src/separate_openapi_schemas/tutorial001_py310.py[ln:1-7]!}
{!> ../../docs_src/separate_openapi_schemas/tutorial001_py310.py[ln:1-7]!}
# Code unterhalb weggelassen 👇
```
@@ -22,7 +22,7 @@ Nehmen wir an, Sie haben ein Pydantic-Modell mit Defaultwerten wie dieses:
<summary>👀 Vollständige Dateivorschau</summary>
```Python
{!> ../../../docs_src/separate_openapi_schemas/tutorial001_py310.py!}
{!> ../../docs_src/separate_openapi_schemas/tutorial001_py310.py!}
```
</details>
@@ -32,7 +32,7 @@ Nehmen wir an, Sie haben ein Pydantic-Modell mit Defaultwerten wie dieses:
//// tab | Python 3.9+
```Python hl_lines="9"
{!> ../../../docs_src/separate_openapi_schemas/tutorial001_py39.py[ln:1-9]!}
{!> ../../docs_src/separate_openapi_schemas/tutorial001_py39.py[ln:1-9]!}
# Code unterhalb weggelassen 👇
```
@@ -41,7 +41,7 @@ Nehmen wir an, Sie haben ein Pydantic-Modell mit Defaultwerten wie dieses:
<summary>👀 Vollständige Dateivorschau</summary>
```Python
{!> ../../../docs_src/separate_openapi_schemas/tutorial001_py39.py!}
{!> ../../docs_src/separate_openapi_schemas/tutorial001_py39.py!}
```
</details>
@@ -51,7 +51,7 @@ Nehmen wir an, Sie haben ein Pydantic-Modell mit Defaultwerten wie dieses:
//// tab | Python 3.8+
```Python hl_lines="9"
{!> ../../../docs_src/separate_openapi_schemas/tutorial001.py[ln:1-9]!}
{!> ../../docs_src/separate_openapi_schemas/tutorial001.py[ln:1-9]!}
# Code unterhalb weggelassen 👇
```
@@ -60,7 +60,7 @@ Nehmen wir an, Sie haben ein Pydantic-Modell mit Defaultwerten wie dieses:
<summary>👀 Vollständige Dateivorschau</summary>
```Python
{!> ../../../docs_src/separate_openapi_schemas/tutorial001.py!}
{!> ../../docs_src/separate_openapi_schemas/tutorial001.py!}
```
</details>
@@ -74,7 +74,7 @@ Wenn Sie dieses Modell wie hier als Eingabe verwenden:
//// tab | Python 3.10+
```Python hl_lines="14"
{!> ../../../docs_src/separate_openapi_schemas/tutorial001_py310.py[ln:1-15]!}
{!> ../../docs_src/separate_openapi_schemas/tutorial001_py310.py[ln:1-15]!}
# Code unterhalb weggelassen 👇
```
@@ -83,7 +83,7 @@ Wenn Sie dieses Modell wie hier als Eingabe verwenden:
<summary>👀 Vollständige Dateivorschau</summary>
```Python
{!> ../../../docs_src/separate_openapi_schemas/tutorial001_py310.py!}
{!> ../../docs_src/separate_openapi_schemas/tutorial001_py310.py!}
```
</details>
@@ -93,7 +93,7 @@ Wenn Sie dieses Modell wie hier als Eingabe verwenden:
//// tab | Python 3.9+
```Python hl_lines="16"
{!> ../../../docs_src/separate_openapi_schemas/tutorial001_py39.py[ln:1-17]!}
{!> ../../docs_src/separate_openapi_schemas/tutorial001_py39.py[ln:1-17]!}
# Code unterhalb weggelassen 👇
```
@@ -102,7 +102,7 @@ Wenn Sie dieses Modell wie hier als Eingabe verwenden:
<summary>👀 Vollständige Dateivorschau</summary>
```Python
{!> ../../../docs_src/separate_openapi_schemas/tutorial001_py39.py!}
{!> ../../docs_src/separate_openapi_schemas/tutorial001_py39.py!}
```
</details>
@@ -112,7 +112,7 @@ Wenn Sie dieses Modell wie hier als Eingabe verwenden:
//// tab | Python 3.8+
```Python hl_lines="16"
{!> ../../../docs_src/separate_openapi_schemas/tutorial001.py[ln:1-17]!}
{!> ../../docs_src/separate_openapi_schemas/tutorial001.py[ln:1-17]!}
# Code unterhalb weggelassen 👇
```
@@ -121,7 +121,7 @@ Wenn Sie dieses Modell wie hier als Eingabe verwenden:
<summary>👀 Vollständige Dateivorschau</summary>
```Python
{!> ../../../docs_src/separate_openapi_schemas/tutorial001.py!}
{!> ../../docs_src/separate_openapi_schemas/tutorial001.py!}
```
</details>
@@ -145,7 +145,7 @@ Wenn Sie jedoch dasselbe Modell als Ausgabe verwenden, wie hier:
//// tab | Python 3.10+
```Python hl_lines="19"
{!> ../../../docs_src/separate_openapi_schemas/tutorial001_py310.py!}
{!> ../../docs_src/separate_openapi_schemas/tutorial001_py310.py!}
```
////
@@ -153,7 +153,7 @@ Wenn Sie jedoch dasselbe Modell als Ausgabe verwenden, wie hier:
//// tab | Python 3.9+
```Python hl_lines="21"
{!> ../../../docs_src/separate_openapi_schemas/tutorial001_py39.py!}
{!> ../../docs_src/separate_openapi_schemas/tutorial001_py39.py!}
```
////
@@ -161,7 +161,7 @@ Wenn Sie jedoch dasselbe Modell als Ausgabe verwenden, wie hier:
//// tab | Python 3.8+
```Python hl_lines="21"
{!> ../../../docs_src/separate_openapi_schemas/tutorial001.py!}
{!> ../../docs_src/separate_openapi_schemas/tutorial001.py!}
```
////
@@ -226,7 +226,7 @@ Unterstützung für `separate_input_output_schemas` wurde in FastAPI `0.102.0` h
//// tab | Python 3.10+
```Python hl_lines="10"
{!> ../../../docs_src/separate_openapi_schemas/tutorial002_py310.py!}
{!> ../../docs_src/separate_openapi_schemas/tutorial002_py310.py!}
```
////
@@ -234,7 +234,7 @@ Unterstützung für `separate_input_output_schemas` wurde in FastAPI `0.102.0` h
//// tab | Python 3.9+
```Python hl_lines="12"
{!> ../../../docs_src/separate_openapi_schemas/tutorial002_py39.py!}
{!> ../../docs_src/separate_openapi_schemas/tutorial002_py39.py!}
```
////
@@ -242,7 +242,7 @@ Unterstützung für `separate_input_output_schemas` wurde in FastAPI `0.102.0` h
//// tab | Python 3.8+
```Python hl_lines="12"
{!> ../../../docs_src/separate_openapi_schemas/tutorial002.py!}
{!> ../../docs_src/separate_openapi_schemas/tutorial002.py!}
```
////

View File

@@ -94,7 +94,7 @@ Seine Schlüssel-Merkmale sind:
„_Ehrlich, was Du gebaut hast, sieht super solide und poliert aus. In vielerlei Hinsicht ist es so, wie ich **Hug** haben wollte es ist wirklich inspirierend, jemanden so etwas bauen zu sehen._“
<div style="text-align: right; margin-right: 10%;">Timothy Crosley - <strong>Autor von <a href="https://www.hug.rest/" target="_blank">Hug</a></strong> <a href="https://news.ycombinator.com/item?id=19455465" target="_blank"><small>(Ref)</small></a></div>
<div style="text-align: right; margin-right: 10%;">Timothy Crosley - <strong>Autor von <a href="https://github.com/hugapi/hug" target="_blank">Hug</a></strong> <a href="https://news.ycombinator.com/item?id=19455465" target="_blank"><small>(Ref)</small></a></div>
---

View File

@@ -23,7 +23,7 @@ Wenn Sie ein Python-Experte sind und bereits alles über Typhinweise wissen, üb
Fangen wir mit einem einfachen Beispiel an:
```Python
{!../../../docs_src/python_types/tutorial001.py!}
{!../../docs_src/python_types/tutorial001.py!}
```
Dieses Programm gibt aus:
@@ -39,7 +39,7 @@ Die Funktion macht Folgendes:
* <abbr title="Füge zu einer Einheit zusammen, eins nach dem anderen.">Verkettet</abbr> sie mit einem Leerzeichen in der Mitte.
```Python hl_lines="2"
{!../../../docs_src/python_types/tutorial001.py!}
{!../../docs_src/python_types/tutorial001.py!}
```
### Bearbeiten Sie es
@@ -83,7 +83,7 @@ Das war's.
Das sind die „Typhinweise“:
```Python hl_lines="1"
{!../../../docs_src/python_types/tutorial002.py!}
{!../../docs_src/python_types/tutorial002.py!}
```
Das ist nicht das gleiche wie das Deklarieren von Defaultwerten, wie es hier der Fall ist:
@@ -113,7 +113,7 @@ Hier können Sie durch die Optionen blättern, bis Sie diejenige finden, bei der
Sehen Sie sich diese Funktion an, sie hat bereits Typhinweise:
```Python hl_lines="1"
{!../../../docs_src/python_types/tutorial003.py!}
{!../../docs_src/python_types/tutorial003.py!}
```
Da der Editor die Typen der Variablen kennt, erhalten Sie nicht nur Code-Vervollständigung, sondern auch eine Fehlerprüfung:
@@ -123,7 +123,7 @@ Da der Editor die Typen der Variablen kennt, erhalten Sie nicht nur Code-Vervoll
Jetzt, da Sie wissen, dass Sie das reparieren müssen, konvertieren Sie `age` mittels `str(age)` in einen String:
```Python hl_lines="2"
{!../../../docs_src/python_types/tutorial004.py!}
{!../../docs_src/python_types/tutorial004.py!}
```
## Deklarieren von Typen
@@ -144,7 +144,7 @@ Zum Beispiel diese:
* `bytes`
```Python hl_lines="1"
{!../../../docs_src/python_types/tutorial005.py!}
{!../../docs_src/python_types/tutorial005.py!}
```
### Generische Typen mit Typ-Parametern
@@ -182,7 +182,7 @@ Als Typ nehmen Sie `list`.
Da die Liste ein Typ ist, welcher innere Typen enthält, werden diese von eckigen Klammern umfasst:
```Python hl_lines="1"
{!> ../../../docs_src/python_types/tutorial006_py39.py!}
{!> ../../docs_src/python_types/tutorial006_py39.py!}
```
////
@@ -192,7 +192,7 @@ Da die Liste ein Typ ist, welcher innere Typen enthält, werden diese von eckige
Von `typing` importieren Sie `List` (mit Großbuchstaben `L`):
```Python hl_lines="1"
{!> ../../../docs_src/python_types/tutorial006.py!}
{!> ../../docs_src/python_types/tutorial006.py!}
```
Deklarieren Sie die Variable mit der gleichen Doppelpunkt-Syntax (`:`).
@@ -202,7 +202,7 @@ Als Typ nehmen Sie das `List`, das Sie von `typing` importiert haben.
Da die Liste ein Typ ist, welcher innere Typen enthält, werden diese von eckigen Klammern umfasst:
```Python hl_lines="4"
{!> ../../../docs_src/python_types/tutorial006.py!}
{!> ../../docs_src/python_types/tutorial006.py!}
```
////
@@ -240,7 +240,7 @@ Das Gleiche gilt für die Deklaration eines Tupels `tuple` und einer Men
//// tab | Python 3.9+
```Python hl_lines="1"
{!> ../../../docs_src/python_types/tutorial007_py39.py!}
{!> ../../docs_src/python_types/tutorial007_py39.py!}
```
////
@@ -248,7 +248,7 @@ Das Gleiche gilt für die Deklaration eines Tupels `tuple` und einer Men
//// tab | Python 3.8+
```Python hl_lines="1 4"
{!> ../../../docs_src/python_types/tutorial007.py!}
{!> ../../docs_src/python_types/tutorial007.py!}
```
////
@@ -269,7 +269,7 @@ Der zweite Typ-Parameter ist für die Werte des `dict`:
//// tab | Python 3.9+
```Python hl_lines="1"
{!> ../../../docs_src/python_types/tutorial008_py39.py!}
{!> ../../docs_src/python_types/tutorial008_py39.py!}
```
////
@@ -277,7 +277,7 @@ Der zweite Typ-Parameter ist für die Werte des `dict`:
//// tab | Python 3.8+
```Python hl_lines="1 4"
{!> ../../../docs_src/python_types/tutorial008.py!}
{!> ../../docs_src/python_types/tutorial008.py!}
```
////
@@ -299,7 +299,7 @@ In Python 3.10 gibt es zusätzlich eine **neue Syntax**, die es erlaubt, die mö
//// tab | Python 3.10+
```Python hl_lines="1"
{!> ../../../docs_src/python_types/tutorial008b_py310.py!}
{!> ../../docs_src/python_types/tutorial008b_py310.py!}
```
////
@@ -307,7 +307,7 @@ In Python 3.10 gibt es zusätzlich eine **neue Syntax**, die es erlaubt, die mö
//// tab | Python 3.8+
```Python hl_lines="1 4"
{!> ../../../docs_src/python_types/tutorial008b.py!}
{!> ../../docs_src/python_types/tutorial008b.py!}
```
////
@@ -321,7 +321,7 @@ Sie können deklarieren, dass ein Wert ein `str`, aber vielleicht auch `None` se
In Python 3.6 und darüber (inklusive Python 3.10) können Sie das deklarieren, indem Sie `Optional` vom `typing` Modul importieren und verwenden.
```Python hl_lines="1 4"
{!../../../docs_src/python_types/tutorial009.py!}
{!../../docs_src/python_types/tutorial009.py!}
```
Wenn Sie `Optional[str]` anstelle von nur `str` verwenden, wird Ihr Editor Ihnen dabei helfen, Fehler zu erkennen, bei denen Sie annehmen könnten, dass ein Wert immer eine String (`str`) ist, obwohl er auch `None` sein könnte.
@@ -333,7 +333,7 @@ Das bedeutet auch, dass Sie in Python 3.10 `Something | None` verwenden können:
//// tab | Python 3.10+
```Python hl_lines="1"
{!> ../../../docs_src/python_types/tutorial009_py310.py!}
{!> ../../docs_src/python_types/tutorial009_py310.py!}
```
////
@@ -341,7 +341,7 @@ Das bedeutet auch, dass Sie in Python 3.10 `Something | None` verwenden können:
//// tab | Python 3.8+
```Python hl_lines="1 4"
{!> ../../../docs_src/python_types/tutorial009.py!}
{!> ../../docs_src/python_types/tutorial009.py!}
```
////
@@ -349,7 +349,7 @@ Das bedeutet auch, dass Sie in Python 3.10 `Something | None` verwenden können:
//// tab | Python 3.8+ Alternative
```Python hl_lines="1 4"
{!> ../../../docs_src/python_types/tutorial009b.py!}
{!> ../../docs_src/python_types/tutorial009b.py!}
```
////
@@ -370,7 +370,7 @@ Es geht nur um Wörter und Namen. Aber diese Worte können beeinflussen, wie Sie
Nehmen wir zum Beispiel diese Funktion:
```Python hl_lines="1 4"
{!../../../docs_src/python_types/tutorial009c.py!}
{!../../docs_src/python_types/tutorial009c.py!}
```
Der Parameter `name` ist definiert als `Optional[str]`, aber er ist **nicht optional**, Sie können die Funktion nicht ohne diesen Parameter aufrufen:
@@ -388,7 +388,7 @@ say_hi(name=None) # Das funktioniert, None is gültig 🎉
Die gute Nachricht ist, dass Sie sich darüber keine Sorgen mehr machen müssen, wenn Sie Python 3.10 verwenden, da Sie einfach `|` verwenden können, um Vereinigungen von Typen zu definieren:
```Python hl_lines="1 4"
{!../../../docs_src/python_types/tutorial009c_py310.py!}
{!../../docs_src/python_types/tutorial009c_py310.py!}
```
Und dann müssen Sie sich nicht mehr um Namen wie `Optional` und `Union` kümmern. 😎
@@ -452,13 +452,13 @@ Sie können auch eine Klasse als Typ einer Variablen deklarieren.
Nehmen wir an, Sie haben eine Klasse `Person`, mit einem Namen:
```Python hl_lines="1-3"
{!../../../docs_src/python_types/tutorial010.py!}
{!../../docs_src/python_types/tutorial010.py!}
```
Dann können Sie eine Variable vom Typ `Person` deklarieren:
```Python hl_lines="6"
{!../../../docs_src/python_types/tutorial010.py!}
{!../../docs_src/python_types/tutorial010.py!}
```
Und wiederum bekommen Sie die volle Editor-Unterstützung:
@@ -486,7 +486,7 @@ Ein Beispiel aus der offiziellen Pydantic Dokumentation:
//// tab | Python 3.10+
```Python
{!> ../../../docs_src/python_types/tutorial011_py310.py!}
{!> ../../docs_src/python_types/tutorial011_py310.py!}
```
////
@@ -494,7 +494,7 @@ Ein Beispiel aus der offiziellen Pydantic Dokumentation:
//// tab | Python 3.9+
```Python
{!> ../../../docs_src/python_types/tutorial011_py39.py!}
{!> ../../docs_src/python_types/tutorial011_py39.py!}
```
////
@@ -502,7 +502,7 @@ Ein Beispiel aus der offiziellen Pydantic Dokumentation:
//// tab | Python 3.8+
```Python
{!> ../../../docs_src/python_types/tutorial011.py!}
{!> ../../docs_src/python_types/tutorial011.py!}
```
////
@@ -532,7 +532,7 @@ Python bietet auch die Möglichkeit, **zusätzliche Metadaten** in Typhinweisen
In Python 3.9 ist `Annotated` ein Teil der Standardbibliothek, Sie können es von `typing` importieren.
```Python hl_lines="1 4"
{!> ../../../docs_src/python_types/tutorial013_py39.py!}
{!> ../../docs_src/python_types/tutorial013_py39.py!}
```
////
@@ -544,7 +544,7 @@ In Versionen niedriger als Python 3.9 importieren Sie `Annotated` von `typing_ex
Es wird bereits mit **FastAPI** installiert sein.
```Python hl_lines="1 4"
{!> ../../../docs_src/python_types/tutorial013.py!}
{!> ../../docs_src/python_types/tutorial013.py!}
```
////

View File

@@ -16,7 +16,7 @@ Hierzu zählen beispielsweise:
Importieren Sie zunächst `BackgroundTasks` und definieren Sie einen Parameter in Ihrer *Pfadoperation-Funktion* mit der Typdeklaration `BackgroundTasks`:
```Python hl_lines="1 13"
{!../../../docs_src/background_tasks/tutorial001.py!}
{!../../docs_src/background_tasks/tutorial001.py!}
```
**FastAPI** erstellt für Sie das Objekt vom Typ `BackgroundTasks` und übergibt es als diesen Parameter.
@@ -34,7 +34,7 @@ In diesem Fall schreibt die Taskfunktion in eine Datei (den Versand einer E-Mail
Und da der Schreibvorgang nicht `async` und `await` verwendet, definieren wir die Funktion mit normalem `def`:
```Python hl_lines="6-9"
{!../../../docs_src/background_tasks/tutorial001.py!}
{!../../docs_src/background_tasks/tutorial001.py!}
```
## Den Hintergrundtask hinzufügen
@@ -42,7 +42,7 @@ Und da der Schreibvorgang nicht `async` und `await` verwendet, definieren wir di
Übergeben Sie innerhalb Ihrer *Pfadoperation-Funktion* Ihre Taskfunktion mit der Methode `.add_task()` an das *Hintergrundtasks*-Objekt:
```Python hl_lines="14"
{!../../../docs_src/background_tasks/tutorial001.py!}
{!../../docs_src/background_tasks/tutorial001.py!}
```
`.add_task()` erhält als Argumente:
@@ -60,7 +60,7 @@ Die Verwendung von `BackgroundTasks` funktioniert auch mit dem <abbr title="Einb
//// tab | Python 3.10+
```Python hl_lines="13 15 22 25"
{!> ../../../docs_src/background_tasks/tutorial002_an_py310.py!}
{!> ../../docs_src/background_tasks/tutorial002_an_py310.py!}
```
////
@@ -68,7 +68,7 @@ Die Verwendung von `BackgroundTasks` funktioniert auch mit dem <abbr title="Einb
//// tab | Python 3.9+
```Python hl_lines="13 15 22 25"
{!> ../../../docs_src/background_tasks/tutorial002_an_py39.py!}
{!> ../../docs_src/background_tasks/tutorial002_an_py39.py!}
```
////
@@ -76,7 +76,7 @@ Die Verwendung von `BackgroundTasks` funktioniert auch mit dem <abbr title="Einb
//// tab | Python 3.8+
```Python hl_lines="14 16 23 26"
{!> ../../../docs_src/background_tasks/tutorial002_an.py!}
{!> ../../docs_src/background_tasks/tutorial002_an.py!}
```
////
@@ -90,7 +90,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="11 13 20 23"
{!> ../../../docs_src/background_tasks/tutorial002_py310.py!}
{!> ../../docs_src/background_tasks/tutorial002_py310.py!}
```
////
@@ -104,7 +104,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="13 15 22 25"
{!> ../../../docs_src/background_tasks/tutorial002.py!}
{!> ../../docs_src/background_tasks/tutorial002.py!}
```
////

View File

@@ -86,7 +86,7 @@ Sie können die *Pfadoperationen* für dieses Modul mit `APIRouter` erstellen.
Sie importieren ihn und erstellen eine „Instanz“ auf die gleiche Weise wie mit der Klasse `FastAPI`:
```Python hl_lines="1 3" title="app/routers/users.py"
{!../../../docs_src/bigger_applications/app/routers/users.py!}
{!../../docs_src/bigger_applications/app/routers/users.py!}
```
### *Pfadoperationen* mit `APIRouter`
@@ -96,7 +96,7 @@ Und dann verwenden Sie ihn, um Ihre *Pfadoperationen* zu deklarieren.
Verwenden Sie ihn auf die gleiche Weise wie die Klasse `FastAPI`:
```Python hl_lines="6 11 16" title="app/routers/users.py"
{!../../../docs_src/bigger_applications/app/routers/users.py!}
{!../../docs_src/bigger_applications/app/routers/users.py!}
```
Sie können sich `APIRouter` als eine „Mini-`FastAPI`“-Klasse vorstellen.
@@ -124,7 +124,7 @@ Wir werden nun eine einfache Abhängigkeit verwenden, um einen benutzerdefiniert
//// tab | Python 3.9+
```Python hl_lines="3 6-8" title="app/dependencies.py"
{!> ../../../docs_src/bigger_applications/app_an_py39/dependencies.py!}
{!> ../../docs_src/bigger_applications/app_an_py39/dependencies.py!}
```
////
@@ -132,7 +132,7 @@ Wir werden nun eine einfache Abhängigkeit verwenden, um einen benutzerdefiniert
//// tab | Python 3.8+
```Python hl_lines="1 5-7" title="app/dependencies.py"
{!> ../../../docs_src/bigger_applications/app_an/dependencies.py!}
{!> ../../docs_src/bigger_applications/app_an/dependencies.py!}
```
////
@@ -146,7 +146,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="1 4-6" title="app/dependencies.py"
{!> ../../../docs_src/bigger_applications/app/dependencies.py!}
{!> ../../docs_src/bigger_applications/app/dependencies.py!}
```
////
@@ -182,7 +182,7 @@ Wir wissen, dass alle *Pfadoperationen* in diesem Modul folgendes haben:
Anstatt also alles zu jeder *Pfadoperation* hinzuzufügen, können wir es dem `APIRouter` hinzufügen.
```Python hl_lines="5-10 16 21" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
{!../../docs_src/bigger_applications/app/routers/items.py!}
```
Da der Pfad jeder *Pfadoperation* mit `/` beginnen muss, wie in:
@@ -243,7 +243,7 @@ Und wir müssen die Abhängigkeitsfunktion aus dem Modul `app.dependencies` impo
Daher verwenden wir einen relativen Import mit `..` für die Abhängigkeiten:
```Python hl_lines="3" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
{!../../docs_src/bigger_applications/app/routers/items.py!}
```
#### Wie relative Importe funktionieren
@@ -316,7 +316,7 @@ Wir fügen weder das Präfix `/items` noch `tags=["items"]` zu jeder *Pfadoperat
Aber wir können immer noch _mehr_ `tags` hinzufügen, die auf eine bestimmte *Pfadoperation* angewendet werden, sowie einige zusätzliche `responses`, die speziell für diese *Pfadoperation* gelten:
```Python hl_lines="30-31" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
{!../../docs_src/bigger_applications/app/routers/items.py!}
```
/// tip | "Tipp"
@@ -344,7 +344,7 @@ Sie importieren und erstellen wie gewohnt eine `FastAPI`-Klasse.
Und wir können sogar [globale Abhängigkeiten](dependencies/global-dependencies.md){.internal-link target=_blank} deklarieren, die mit den Abhängigkeiten für jeden `APIRouter` kombiniert werden:
```Python hl_lines="1 3 7" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
{!../../docs_src/bigger_applications/app/main.py!}
```
### Den `APIRouter` importieren
@@ -352,7 +352,7 @@ Und wir können sogar [globale Abhängigkeiten](dependencies/global-dependencies
Jetzt importieren wir die anderen Submodule, die `APIRouter` haben:
```Python hl_lines="4-5" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
{!../../docs_src/bigger_applications/app/main.py!}
```
Da es sich bei den Dateien `app/routers/users.py` und `app/routers/items.py` um Submodule handelt, die Teil desselben Python-Packages `app` sind, können wir einen einzelnen Punkt `.` verwenden, um sie mit „relativen Imports“ zu importieren.
@@ -417,7 +417,7 @@ würde der `router` von `users` den von `items` überschreiben und wir könnten
Um also beide in derselben Datei verwenden zu können, importieren wir die Submodule direkt:
```Python hl_lines="5" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
{!../../docs_src/bigger_applications/app/main.py!}
```
@@ -426,7 +426,7 @@ Um also beide in derselben Datei verwenden zu können, importieren wir die Submo
Inkludieren wir nun die `router` aus diesen Submodulen `users` und `items`:
```Python hl_lines="10-11" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
{!../../docs_src/bigger_applications/app/main.py!}
```
/// info
@@ -468,7 +468,7 @@ Sie enthält einen `APIRouter` mit einigen administrativen *Pfadoperationen*, di
In diesem Beispiel wird es ganz einfach sein. Nehmen wir jedoch an, dass wir, da sie mit anderen Projekten in der Organisation geteilt wird, sie nicht ändern und kein `prefix`, `dependencies`, `tags`, usw. direkt zum `APIRouter` hinzufügen können:
```Python hl_lines="3" title="app/internal/admin.py"
{!../../../docs_src/bigger_applications/app/internal/admin.py!}
{!../../docs_src/bigger_applications/app/internal/admin.py!}
```
Aber wir möchten immer noch ein benutzerdefiniertes `prefix` festlegen, wenn wir den `APIRouter` einbinden, sodass alle seine *Pfadoperationen* mit `/admin` beginnen, wir möchten es mit den `dependencies` sichern, die wir bereits für dieses Projekt haben, und wir möchten `tags` und `responses` hinzufügen.
@@ -476,7 +476,7 @@ Aber wir möchten immer noch ein benutzerdefiniertes `prefix` festlegen, wenn wi
Wir können das alles deklarieren, ohne den ursprünglichen `APIRouter` ändern zu müssen, indem wir diese Parameter an `app.include_router()` übergeben:
```Python hl_lines="14-17" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
{!../../docs_src/bigger_applications/app/main.py!}
```
Auf diese Weise bleibt der ursprüngliche `APIRouter` unverändert, sodass wir dieselbe `app/internal/admin.py`-Datei weiterhin mit anderen Projekten in der Organisation teilen können.
@@ -499,7 +499,7 @@ Wir können *Pfadoperationen* auch direkt zur `FastAPI`-App hinzufügen.
Hier machen wir es ... nur um zu zeigen, dass wir es können 🤷:
```Python hl_lines="21-23" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
{!../../docs_src/bigger_applications/app/main.py!}
```
und es wird korrekt funktionieren, zusammen mit allen anderen *Pfadoperationen*, die mit `app.include_router()` hinzugefügt wurden.

View File

@@ -9,7 +9,7 @@ Importieren Sie es zuerst:
//// tab | Python 3.10+
```Python hl_lines="4"
{!> ../../../docs_src/body_fields/tutorial001_an_py310.py!}
{!> ../../docs_src/body_fields/tutorial001_an_py310.py!}
```
////
@@ -17,7 +17,7 @@ Importieren Sie es zuerst:
//// tab | Python 3.9+
```Python hl_lines="4"
{!> ../../../docs_src/body_fields/tutorial001_an_py39.py!}
{!> ../../docs_src/body_fields/tutorial001_an_py39.py!}
```
////
@@ -25,7 +25,7 @@ Importieren Sie es zuerst:
//// tab | Python 3.8+
```Python hl_lines="4"
{!> ../../../docs_src/body_fields/tutorial001_an.py!}
{!> ../../docs_src/body_fields/tutorial001_an.py!}
```
////
@@ -39,7 +39,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="2"
{!> ../../../docs_src/body_fields/tutorial001_py310.py!}
{!> ../../docs_src/body_fields/tutorial001_py310.py!}
```
////
@@ -53,7 +53,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="4"
{!> ../../../docs_src/body_fields/tutorial001.py!}
{!> ../../docs_src/body_fields/tutorial001.py!}
```
////
@@ -71,7 +71,7 @@ Dann können Sie `Field` mit Modellattributen deklarieren:
//// tab | Python 3.10+
```Python hl_lines="11-14"
{!> ../../../docs_src/body_fields/tutorial001_an_py310.py!}
{!> ../../docs_src/body_fields/tutorial001_an_py310.py!}
```
////
@@ -79,7 +79,7 @@ Dann können Sie `Field` mit Modellattributen deklarieren:
//// tab | Python 3.9+
```Python hl_lines="11-14"
{!> ../../../docs_src/body_fields/tutorial001_an_py39.py!}
{!> ../../docs_src/body_fields/tutorial001_an_py39.py!}
```
////
@@ -87,7 +87,7 @@ Dann können Sie `Field` mit Modellattributen deklarieren:
//// tab | Python 3.8+
```Python hl_lines="12-15"
{!> ../../../docs_src/body_fields/tutorial001_an.py!}
{!> ../../docs_src/body_fields/tutorial001_an.py!}
```
////
@@ -101,7 +101,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="9-12"
{!> ../../../docs_src/body_fields/tutorial001_py310.py!}
{!> ../../docs_src/body_fields/tutorial001_py310.py!}
```
////
@@ -115,7 +115,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="11-14"
{!> ../../../docs_src/body_fields/tutorial001.py!}
{!> ../../docs_src/body_fields/tutorial001.py!}
```
////

View File

@@ -11,7 +11,7 @@ Und Sie können auch Body-Parameter als optional kennzeichnen, indem Sie den Def
//// tab | Python 3.10+
```Python hl_lines="18-20"
{!> ../../../docs_src/body_multiple_params/tutorial001_an_py310.py!}
{!> ../../docs_src/body_multiple_params/tutorial001_an_py310.py!}
```
////
@@ -19,7 +19,7 @@ Und Sie können auch Body-Parameter als optional kennzeichnen, indem Sie den Def
//// tab | Python 3.9+
```Python hl_lines="18-20"
{!> ../../../docs_src/body_multiple_params/tutorial001_an_py39.py!}
{!> ../../docs_src/body_multiple_params/tutorial001_an_py39.py!}
```
////
@@ -27,7 +27,7 @@ Und Sie können auch Body-Parameter als optional kennzeichnen, indem Sie den Def
//// tab | Python 3.8+
```Python hl_lines="19-21"
{!> ../../../docs_src/body_multiple_params/tutorial001_an.py!}
{!> ../../docs_src/body_multiple_params/tutorial001_an.py!}
```
////
@@ -41,7 +41,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="17-19"
{!> ../../../docs_src/body_multiple_params/tutorial001_py310.py!}
{!> ../../docs_src/body_multiple_params/tutorial001_py310.py!}
```
////
@@ -55,7 +55,7 @@ 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.py!}
```
////
@@ -84,7 +84,7 @@ 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!}
{!> ../../docs_src/body_multiple_params/tutorial002_py310.py!}
```
////
@@ -92,7 +92,7 @@ Aber Sie können auch mehrere Body-Parameter deklarieren, z. B. `item` und `user
//// tab | Python 3.8+
```Python hl_lines="22"
{!> ../../../docs_src/body_multiple_params/tutorial002.py!}
{!> ../../docs_src/body_multiple_params/tutorial002.py!}
```
////
@@ -139,7 +139,7 @@ Aber Sie können **FastAPI** instruieren, ihn als weiteren Body-Schlüssel zu er
//// tab | Python 3.10+
```Python hl_lines="23"
{!> ../../../docs_src/body_multiple_params/tutorial003_an_py310.py!}
{!> ../../docs_src/body_multiple_params/tutorial003_an_py310.py!}
```
////
@@ -147,7 +147,7 @@ Aber Sie können **FastAPI** instruieren, ihn als weiteren Body-Schlüssel zu er
//// tab | Python 3.9+
```Python hl_lines="23"
{!> ../../../docs_src/body_multiple_params/tutorial003_an_py39.py!}
{!> ../../docs_src/body_multiple_params/tutorial003_an_py39.py!}
```
////
@@ -155,7 +155,7 @@ Aber Sie können **FastAPI** instruieren, ihn als weiteren Body-Schlüssel zu er
//// tab | Python 3.8+
```Python hl_lines="24"
{!> ../../../docs_src/body_multiple_params/tutorial003_an.py!}
{!> ../../docs_src/body_multiple_params/tutorial003_an.py!}
```
////
@@ -169,7 +169,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="20"
{!> ../../../docs_src/body_multiple_params/tutorial003_py310.py!}
{!> ../../docs_src/body_multiple_params/tutorial003_py310.py!}
```
////
@@ -183,7 +183,7 @@ 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.py!}
```
////
@@ -229,7 +229,7 @@ Zum Beispiel:
//// tab | Python 3.10+
```Python hl_lines="27"
{!> ../../../docs_src/body_multiple_params/tutorial004_an_py310.py!}
{!> ../../docs_src/body_multiple_params/tutorial004_an_py310.py!}
```
////
@@ -237,7 +237,7 @@ Zum Beispiel:
//// tab | Python 3.9+
```Python hl_lines="27"
{!> ../../../docs_src/body_multiple_params/tutorial004_an_py39.py!}
{!> ../../docs_src/body_multiple_params/tutorial004_an_py39.py!}
```
////
@@ -245,7 +245,7 @@ Zum Beispiel:
//// tab | Python 3.8+
```Python hl_lines="28"
{!> ../../../docs_src/body_multiple_params/tutorial004_an.py!}
{!> ../../docs_src/body_multiple_params/tutorial004_an.py!}
```
////
@@ -259,7 +259,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="25"
{!> ../../../docs_src/body_multiple_params/tutorial004_py310.py!}
{!> ../../docs_src/body_multiple_params/tutorial004_py310.py!}
```
////
@@ -273,7 +273,7 @@ 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.py!}
```
////
@@ -301,7 +301,7 @@ so wie in:
//// tab | Python 3.10+
```Python hl_lines="17"
{!> ../../../docs_src/body_multiple_params/tutorial005_an_py310.py!}
{!> ../../docs_src/body_multiple_params/tutorial005_an_py310.py!}
```
////
@@ -309,7 +309,7 @@ so wie in:
//// tab | Python 3.9+
```Python hl_lines="17"
{!> ../../../docs_src/body_multiple_params/tutorial005_an_py39.py!}
{!> ../../docs_src/body_multiple_params/tutorial005_an_py39.py!}
```
////
@@ -317,7 +317,7 @@ so wie in:
//// tab | Python 3.8+
```Python hl_lines="18"
{!> ../../../docs_src/body_multiple_params/tutorial005_an.py!}
{!> ../../docs_src/body_multiple_params/tutorial005_an.py!}
```
////
@@ -331,7 +331,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="15"
{!> ../../../docs_src/body_multiple_params/tutorial005_py310.py!}
{!> ../../docs_src/body_multiple_params/tutorial005_py310.py!}
```
////
@@ -345,7 +345,7 @@ 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.py!}
```
////

View File

@@ -9,7 +9,7 @@ Sie können ein Attribut als Kindtyp definieren, zum Beispiel eine Python-`list`
//// tab | Python 3.10+
```Python hl_lines="12"
{!> ../../../docs_src/body_nested_models/tutorial001_py310.py!}
{!> ../../docs_src/body_nested_models/tutorial001_py310.py!}
```
////
@@ -17,7 +17,7 @@ Sie können ein Attribut als Kindtyp definieren, zum Beispiel eine Python-`list`
//// tab | Python 3.8+
```Python hl_lines="14"
{!> ../../../docs_src/body_nested_models/tutorial001.py!}
{!> ../../docs_src/body_nested_models/tutorial001.py!}
```
////
@@ -35,7 +35,7 @@ In Python 3.9 oder darüber können Sie einfach `list` verwenden, um diese Typan
In Python-Versionen vor 3.9 (3.6 und darüber), müssen Sie zuerst `List` von Pythons Standardmodul `typing` importieren.
```Python hl_lines="1"
{!> ../../../docs_src/body_nested_models/tutorial002.py!}
{!> ../../docs_src/body_nested_models/tutorial002.py!}
```
### Eine `list`e mit einem Typ-Parameter deklarieren
@@ -68,7 +68,7 @@ In unserem Beispiel können wir also bewirken, dass `tags` spezifisch eine „Li
//// tab | Python 3.10+
```Python hl_lines="12"
{!> ../../../docs_src/body_nested_models/tutorial002_py310.py!}
{!> ../../docs_src/body_nested_models/tutorial002_py310.py!}
```
////
@@ -76,7 +76,7 @@ In unserem Beispiel können wir also bewirken, dass `tags` spezifisch eine „Li
//// tab | Python 3.9+
```Python hl_lines="14"
{!> ../../../docs_src/body_nested_models/tutorial002_py39.py!}
{!> ../../docs_src/body_nested_models/tutorial002_py39.py!}
```
////
@@ -84,7 +84,7 @@ In unserem Beispiel können wir also bewirken, dass `tags` spezifisch eine „Li
//// tab | Python 3.8+
```Python hl_lines="14"
{!> ../../../docs_src/body_nested_models/tutorial002.py!}
{!> ../../docs_src/body_nested_models/tutorial002.py!}
```
////
@@ -100,7 +100,7 @@ Deklarieren wir also `tags` als Set von Strings.
//// tab | Python 3.10+
```Python hl_lines="12"
{!> ../../../docs_src/body_nested_models/tutorial003_py310.py!}
{!> ../../docs_src/body_nested_models/tutorial003_py310.py!}
```
////
@@ -108,7 +108,7 @@ Deklarieren wir also `tags` als Set von Strings.
//// tab | Python 3.9+
```Python hl_lines="14"
{!> ../../../docs_src/body_nested_models/tutorial003_py39.py!}
{!> ../../docs_src/body_nested_models/tutorial003_py39.py!}
```
////
@@ -116,7 +116,7 @@ Deklarieren wir also `tags` als Set von Strings.
//// tab | Python 3.8+
```Python hl_lines="1 14"
{!> ../../../docs_src/body_nested_models/tutorial003.py!}
{!> ../../docs_src/body_nested_models/tutorial003.py!}
```
////
@@ -144,7 +144,7 @@ Wir können zum Beispiel ein `Image`-Modell definieren.
//// tab | Python 3.10+
```Python hl_lines="7-9"
{!> ../../../docs_src/body_nested_models/tutorial004_py310.py!}
{!> ../../docs_src/body_nested_models/tutorial004_py310.py!}
```
////
@@ -152,7 +152,7 @@ Wir können zum Beispiel ein `Image`-Modell definieren.
//// tab | Python 3.9+
```Python hl_lines="9-11"
{!> ../../../docs_src/body_nested_models/tutorial004_py39.py!}
{!> ../../docs_src/body_nested_models/tutorial004_py39.py!}
```
////
@@ -160,7 +160,7 @@ Wir können zum Beispiel ein `Image`-Modell definieren.
//// tab | Python 3.8+
```Python hl_lines="9-11"
{!> ../../../docs_src/body_nested_models/tutorial004.py!}
{!> ../../docs_src/body_nested_models/tutorial004.py!}
```
////
@@ -172,7 +172,7 @@ Und dann können wir es als Typ eines Attributes verwenden.
//// tab | Python 3.10+
```Python hl_lines="18"
{!> ../../../docs_src/body_nested_models/tutorial004_py310.py!}
{!> ../../docs_src/body_nested_models/tutorial004_py310.py!}
```
////
@@ -180,7 +180,7 @@ Und dann können wir es als Typ eines Attributes verwenden.
//// tab | Python 3.9+
```Python hl_lines="20"
{!> ../../../docs_src/body_nested_models/tutorial004_py39.py!}
{!> ../../docs_src/body_nested_models/tutorial004_py39.py!}
```
////
@@ -188,7 +188,7 @@ Und dann können wir es als Typ eines Attributes verwenden.
//// tab | Python 3.8+
```Python hl_lines="20"
{!> ../../../docs_src/body_nested_models/tutorial004.py!}
{!> ../../docs_src/body_nested_models/tutorial004.py!}
```
////
@@ -227,7 +227,7 @@ Da wir zum Beispiel im `Image`-Modell ein Feld `url` haben, können wir deklarie
//// tab | Python 3.10+
```Python hl_lines="2 8"
{!> ../../../docs_src/body_nested_models/tutorial005_py310.py!}
{!> ../../docs_src/body_nested_models/tutorial005_py310.py!}
```
////
@@ -235,7 +235,7 @@ Da wir zum Beispiel im `Image`-Modell ein Feld `url` haben, können wir deklarie
//// tab | Python 3.9+
```Python hl_lines="4 10"
{!> ../../../docs_src/body_nested_models/tutorial005_py39.py!}
{!> ../../docs_src/body_nested_models/tutorial005_py39.py!}
```
////
@@ -243,7 +243,7 @@ Da wir zum Beispiel im `Image`-Modell ein Feld `url` haben, können wir deklarie
//// tab | Python 3.8+
```Python hl_lines="4 10"
{!> ../../../docs_src/body_nested_models/tutorial005.py!}
{!> ../../docs_src/body_nested_models/tutorial005.py!}
```
////
@@ -257,7 +257,7 @@ Sie können Pydantic-Modelle auch als Typen innerhalb von `list`, `set`, usw. ve
//// tab | Python 3.10+
```Python hl_lines="18"
{!> ../../../docs_src/body_nested_models/tutorial006_py310.py!}
{!> ../../docs_src/body_nested_models/tutorial006_py310.py!}
```
////
@@ -265,7 +265,7 @@ Sie können Pydantic-Modelle auch als Typen innerhalb von `list`, `set`, usw. ve
//// tab | Python 3.9+
```Python hl_lines="20"
{!> ../../../docs_src/body_nested_models/tutorial006_py39.py!}
{!> ../../docs_src/body_nested_models/tutorial006_py39.py!}
```
////
@@ -273,7 +273,7 @@ Sie können Pydantic-Modelle auch als Typen innerhalb von `list`, `set`, usw. ve
//// tab | Python 3.8+
```Python hl_lines="20"
{!> ../../../docs_src/body_nested_models/tutorial006.py!}
{!> ../../docs_src/body_nested_models/tutorial006.py!}
```
////
@@ -317,7 +317,7 @@ Sie können beliebig tief verschachtelte Modelle definieren:
//// tab | Python 3.10+
```Python hl_lines="7 12 18 21 25"
{!> ../../../docs_src/body_nested_models/tutorial007_py310.py!}
{!> ../../docs_src/body_nested_models/tutorial007_py310.py!}
```
////
@@ -325,7 +325,7 @@ Sie können beliebig tief verschachtelte Modelle definieren:
//// tab | Python 3.9+
```Python hl_lines="9 14 20 23 27"
{!> ../../../docs_src/body_nested_models/tutorial007_py39.py!}
{!> ../../docs_src/body_nested_models/tutorial007_py39.py!}
```
////
@@ -333,7 +333,7 @@ Sie können beliebig tief verschachtelte Modelle definieren:
//// tab | Python 3.8+
```Python hl_lines="9 14 20 23 27"
{!> ../../../docs_src/body_nested_models/tutorial007.py!}
{!> ../../docs_src/body_nested_models/tutorial007.py!}
```
////
@@ -363,7 +363,7 @@ so wie in:
//// tab | Python 3.9+
```Python hl_lines="13"
{!> ../../../docs_src/body_nested_models/tutorial008_py39.py!}
{!> ../../docs_src/body_nested_models/tutorial008_py39.py!}
```
////
@@ -371,7 +371,7 @@ so wie in:
//// tab | Python 3.8+
```Python hl_lines="15"
{!> ../../../docs_src/body_nested_models/tutorial008.py!}
{!> ../../docs_src/body_nested_models/tutorial008.py!}
```
////
@@ -407,7 +407,7 @@ Im folgenden Beispiel akzeptieren Sie irgendein `dict`, solange es `int`-Schlüs
//// tab | Python 3.9+
```Python hl_lines="7"
{!> ../../../docs_src/body_nested_models/tutorial009_py39.py!}
{!> ../../docs_src/body_nested_models/tutorial009_py39.py!}
```
////
@@ -415,7 +415,7 @@ Im folgenden Beispiel akzeptieren Sie irgendein `dict`, solange es `int`-Schlüs
//// tab | Python 3.8+
```Python hl_lines="9"
{!> ../../../docs_src/body_nested_models/tutorial009.py!}
{!> ../../docs_src/body_nested_models/tutorial009.py!}
```
////

View File

@@ -9,7 +9,7 @@ Sie können den `jsonable_encoder` verwenden, um die empfangenen Daten in etwas
//// tab | Python 3.10+
```Python hl_lines="28-33"
{!> ../../../docs_src/body_updates/tutorial001_py310.py!}
{!> ../../docs_src/body_updates/tutorial001_py310.py!}
```
////
@@ -17,7 +17,7 @@ Sie können den `jsonable_encoder` verwenden, um die empfangenen Daten in etwas
//// tab | Python 3.9+
```Python hl_lines="30-35"
{!> ../../../docs_src/body_updates/tutorial001_py39.py!}
{!> ../../docs_src/body_updates/tutorial001_py39.py!}
```
////
@@ -25,7 +25,7 @@ Sie können den `jsonable_encoder` verwenden, um die empfangenen Daten in etwas
//// tab | Python 3.8+
```Python hl_lines="30-35"
{!> ../../../docs_src/body_updates/tutorial001.py!}
{!> ../../docs_src/body_updates/tutorial001.py!}
```
////
@@ -87,7 +87,7 @@ Sie können das verwenden, um ein `dict` zu erstellen, das nur die (im Request)
//// tab | Python 3.10+
```Python hl_lines="32"
{!> ../../../docs_src/body_updates/tutorial002_py310.py!}
{!> ../../docs_src/body_updates/tutorial002_py310.py!}
```
////
@@ -95,7 +95,7 @@ Sie können das verwenden, um ein `dict` zu erstellen, das nur die (im Request)
//// tab | Python 3.9+
```Python hl_lines="34"
{!> ../../../docs_src/body_updates/tutorial002_py39.py!}
{!> ../../docs_src/body_updates/tutorial002_py39.py!}
```
////
@@ -103,7 +103,7 @@ Sie können das verwenden, um ein `dict` zu erstellen, das nur die (im Request)
//// tab | Python 3.8+
```Python hl_lines="34"
{!> ../../../docs_src/body_updates/tutorial002.py!}
{!> ../../docs_src/body_updates/tutorial002.py!}
```
////
@@ -125,7 +125,7 @@ Wie in `stored_item_model.model_copy(update=update_data)`:
//// tab | Python 3.10+
```Python hl_lines="33"
{!> ../../../docs_src/body_updates/tutorial002_py310.py!}
{!> ../../docs_src/body_updates/tutorial002_py310.py!}
```
////
@@ -133,7 +133,7 @@ Wie in `stored_item_model.model_copy(update=update_data)`:
//// tab | Python 3.9+
```Python hl_lines="35"
{!> ../../../docs_src/body_updates/tutorial002_py39.py!}
{!> ../../docs_src/body_updates/tutorial002_py39.py!}
```
////
@@ -141,7 +141,7 @@ Wie in `stored_item_model.model_copy(update=update_data)`:
//// tab | Python 3.8+
```Python hl_lines="35"
{!> ../../../docs_src/body_updates/tutorial002.py!}
{!> ../../docs_src/body_updates/tutorial002.py!}
```
////
@@ -164,7 +164,7 @@ Zusammengefasst, um Teil-Ersetzungen vorzunehmen:
//// tab | Python 3.10+
```Python hl_lines="28-35"
{!> ../../../docs_src/body_updates/tutorial002_py310.py!}
{!> ../../docs_src/body_updates/tutorial002_py310.py!}
```
////
@@ -172,7 +172,7 @@ Zusammengefasst, um Teil-Ersetzungen vorzunehmen:
//// tab | Python 3.9+
```Python hl_lines="30-37"
{!> ../../../docs_src/body_updates/tutorial002_py39.py!}
{!> ../../docs_src/body_updates/tutorial002_py39.py!}
```
////
@@ -180,7 +180,7 @@ Zusammengefasst, um Teil-Ersetzungen vorzunehmen:
//// tab | Python 3.8+
```Python hl_lines="30-37"
{!> ../../../docs_src/body_updates/tutorial002.py!}
{!> ../../docs_src/body_updates/tutorial002.py!}
```
////

View File

@@ -25,7 +25,7 @@ Zuerst müssen Sie `BaseModel` von `pydantic` importieren:
//// tab | Python 3.10+
```Python hl_lines="2"
{!> ../../../docs_src/body/tutorial001_py310.py!}
{!> ../../docs_src/body/tutorial001_py310.py!}
```
////
@@ -33,7 +33,7 @@ Zuerst müssen Sie `BaseModel` von `pydantic` importieren:
//// tab | Python 3.8+
```Python hl_lines="4"
{!> ../../../docs_src/body/tutorial001.py!}
{!> ../../docs_src/body/tutorial001.py!}
```
////
@@ -47,7 +47,7 @@ Verwenden Sie Standard-Python-Typen für die Klassenattribute:
//// tab | Python 3.10+
```Python hl_lines="5-9"
{!> ../../../docs_src/body/tutorial001_py310.py!}
{!> ../../docs_src/body/tutorial001_py310.py!}
```
////
@@ -55,7 +55,7 @@ Verwenden Sie Standard-Python-Typen für die Klassenattribute:
//// tab | Python 3.8+
```Python hl_lines="7-11"
{!> ../../../docs_src/body/tutorial001.py!}
{!> ../../docs_src/body/tutorial001.py!}
```
////
@@ -89,7 +89,7 @@ Um es zu Ihrer *Pfadoperation* hinzuzufügen, deklarieren Sie es auf die gleiche
//// tab | Python 3.10+
```Python hl_lines="16"
{!> ../../../docs_src/body/tutorial001_py310.py!}
{!> ../../docs_src/body/tutorial001_py310.py!}
```
////
@@ -97,7 +97,7 @@ Um es zu Ihrer *Pfadoperation* hinzuzufügen, deklarieren Sie es auf die gleiche
//// tab | Python 3.8+
```Python hl_lines="18"
{!> ../../../docs_src/body/tutorial001.py!}
{!> ../../docs_src/body/tutorial001.py!}
```
////
@@ -170,7 +170,7 @@ Innerhalb der Funktion können Sie alle Attribute des Modells direkt verwenden:
//// tab | Python 3.10+
```Python hl_lines="19"
{!> ../../../docs_src/body/tutorial002_py310.py!}
{!> ../../docs_src/body/tutorial002_py310.py!}
```
////
@@ -178,7 +178,7 @@ Innerhalb der Funktion können Sie alle Attribute des Modells direkt verwenden:
//// tab | Python 3.8+
```Python hl_lines="21"
{!> ../../../docs_src/body/tutorial002.py!}
{!> ../../docs_src/body/tutorial002.py!}
```
////
@@ -192,7 +192,7 @@ Sie können Pfad- und Requestbody-Parameter gleichzeitig deklarieren.
//// tab | Python 3.10+
```Python hl_lines="15-16"
{!> ../../../docs_src/body/tutorial003_py310.py!}
{!> ../../docs_src/body/tutorial003_py310.py!}
```
////
@@ -200,7 +200,7 @@ Sie können Pfad- und Requestbody-Parameter gleichzeitig deklarieren.
//// tab | Python 3.8+
```Python hl_lines="17-18"
{!> ../../../docs_src/body/tutorial003.py!}
{!> ../../docs_src/body/tutorial003.py!}
```
////
@@ -214,7 +214,7 @@ Sie können auch zur gleichen Zeit **Body-**, **Pfad-** und **Query-Parameter**
//// tab | Python 3.10+
```Python hl_lines="16"
{!> ../../../docs_src/body/tutorial004_py310.py!}
{!> ../../docs_src/body/tutorial004_py310.py!}
```
////
@@ -222,7 +222,7 @@ Sie können auch zur gleichen Zeit **Body-**, **Pfad-** und **Query-Parameter**
//// tab | Python 3.8+
```Python hl_lines="18"
{!> ../../../docs_src/body/tutorial004.py!}
{!> ../../docs_src/body/tutorial004.py!}
```
////

View File

@@ -9,7 +9,7 @@ Importieren Sie zuerst `Cookie`:
//// tab | Python 3.10+
```Python hl_lines="3"
{!> ../../../docs_src/cookie_params/tutorial001_an_py310.py!}
{!> ../../docs_src/cookie_params/tutorial001_an_py310.py!}
```
////
@@ -17,7 +17,7 @@ Importieren Sie zuerst `Cookie`:
//// tab | Python 3.9+
```Python hl_lines="3"
{!> ../../../docs_src/cookie_params/tutorial001_an_py39.py!}
{!> ../../docs_src/cookie_params/tutorial001_an_py39.py!}
```
////
@@ -25,7 +25,7 @@ Importieren Sie zuerst `Cookie`:
//// tab | Python 3.8+
```Python hl_lines="3"
{!> ../../../docs_src/cookie_params/tutorial001_an.py!}
{!> ../../docs_src/cookie_params/tutorial001_an.py!}
```
////
@@ -39,7 +39,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="1"
{!> ../../../docs_src/cookie_params/tutorial001_py310.py!}
{!> ../../docs_src/cookie_params/tutorial001_py310.py!}
```
////
@@ -53,7 +53,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="3"
{!> ../../../docs_src/cookie_params/tutorial001.py!}
{!> ../../docs_src/cookie_params/tutorial001.py!}
```
////
@@ -67,7 +67,7 @@ Der erste Wert ist der Typ. Sie können `Cookie` die gehabten Extra Validierungs
//// tab | Python 3.10+
```Python hl_lines="9"
{!> ../../../docs_src/cookie_params/tutorial001_an_py310.py!}
{!> ../../docs_src/cookie_params/tutorial001_an_py310.py!}
```
////
@@ -75,7 +75,7 @@ Der erste Wert ist der Typ. Sie können `Cookie` die gehabten Extra Validierungs
//// tab | Python 3.9+
```Python hl_lines="9"
{!> ../../../docs_src/cookie_params/tutorial001_an_py39.py!}
{!> ../../docs_src/cookie_params/tutorial001_an_py39.py!}
```
////
@@ -83,7 +83,7 @@ Der erste Wert ist der Typ. Sie können `Cookie` die gehabten Extra Validierungs
//// tab | Python 3.8+
```Python hl_lines="10"
{!> ../../../docs_src/cookie_params/tutorial001_an.py!}
{!> ../../docs_src/cookie_params/tutorial001_an.py!}
```
////
@@ -97,7 +97,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7"
{!> ../../../docs_src/cookie_params/tutorial001_py310.py!}
{!> ../../docs_src/cookie_params/tutorial001_py310.py!}
```
////
@@ -111,7 +111,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="9"
{!> ../../../docs_src/cookie_params/tutorial001.py!}
{!> ../../docs_src/cookie_params/tutorial001.py!}
```
////

View File

@@ -9,7 +9,7 @@ Im vorherigen Beispiel haben wir ein `dict` von unserer Abhängigkeit („Depend
//// tab | Python 3.10+
```Python hl_lines="9"
{!> ../../../docs_src/dependencies/tutorial001_an_py310.py!}
{!> ../../docs_src/dependencies/tutorial001_an_py310.py!}
```
////
@@ -17,7 +17,7 @@ Im vorherigen Beispiel haben wir ein `dict` von unserer Abhängigkeit („Depend
//// tab | Python 3.9+
```Python hl_lines="11"
{!> ../../../docs_src/dependencies/tutorial001_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial001_an_py39.py!}
```
////
@@ -25,7 +25,7 @@ Im vorherigen Beispiel haben wir ein `dict` von unserer Abhängigkeit („Depend
//// tab | Python 3.8+
```Python hl_lines="12"
{!> ../../../docs_src/dependencies/tutorial001_an.py!}
{!> ../../docs_src/dependencies/tutorial001_an.py!}
```
////
@@ -39,7 +39,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7"
{!> ../../../docs_src/dependencies/tutorial001_py310.py!}
{!> ../../docs_src/dependencies/tutorial001_py310.py!}
```
////
@@ -53,7 +53,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="11"
{!> ../../../docs_src/dependencies/tutorial001.py!}
{!> ../../docs_src/dependencies/tutorial001.py!}
```
////
@@ -122,7 +122,7 @@ Dann können wir das „Dependable“ `common_parameters` der Abhängigkeit von
//// tab | Python 3.10+
```Python hl_lines="11-15"
{!> ../../../docs_src/dependencies/tutorial002_an_py310.py!}
{!> ../../docs_src/dependencies/tutorial002_an_py310.py!}
```
////
@@ -130,7 +130,7 @@ Dann können wir das „Dependable“ `common_parameters` der Abhängigkeit von
//// tab | Python 3.9+
```Python hl_lines="11-15"
{!> ../../../docs_src/dependencies/tutorial002_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial002_an_py39.py!}
```
////
@@ -138,7 +138,7 @@ Dann können wir das „Dependable“ `common_parameters` der Abhängigkeit von
//// tab | Python 3.8+
```Python hl_lines="12-16"
{!> ../../../docs_src/dependencies/tutorial002_an.py!}
{!> ../../docs_src/dependencies/tutorial002_an.py!}
```
////
@@ -152,7 +152,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="9-13"
{!> ../../../docs_src/dependencies/tutorial002_py310.py!}
{!> ../../docs_src/dependencies/tutorial002_py310.py!}
```
////
@@ -166,7 +166,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="11-15"
{!> ../../../docs_src/dependencies/tutorial002.py!}
{!> ../../docs_src/dependencies/tutorial002.py!}
```
////
@@ -176,7 +176,7 @@ Achten Sie auf die Methode `__init__`, die zum Erstellen der Instanz der Klasse
//// tab | Python 3.10+
```Python hl_lines="12"
{!> ../../../docs_src/dependencies/tutorial002_an_py310.py!}
{!> ../../docs_src/dependencies/tutorial002_an_py310.py!}
```
////
@@ -184,7 +184,7 @@ Achten Sie auf die Methode `__init__`, die zum Erstellen der Instanz der Klasse
//// tab | Python 3.9+
```Python hl_lines="12"
{!> ../../../docs_src/dependencies/tutorial002_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial002_an_py39.py!}
```
////
@@ -192,7 +192,7 @@ Achten Sie auf die Methode `__init__`, die zum Erstellen der Instanz der Klasse
//// tab | Python 3.8+
```Python hl_lines="13"
{!> ../../../docs_src/dependencies/tutorial002_an.py!}
{!> ../../docs_src/dependencies/tutorial002_an.py!}
```
////
@@ -206,7 +206,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="10"
{!> ../../../docs_src/dependencies/tutorial002_py310.py!}
{!> ../../docs_src/dependencies/tutorial002_py310.py!}
```
////
@@ -220,7 +220,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="12"
{!> ../../../docs_src/dependencies/tutorial002.py!}
{!> ../../docs_src/dependencies/tutorial002.py!}
```
////
@@ -230,7 +230,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
//// tab | Python 3.10+
```Python hl_lines="8"
{!> ../../../docs_src/dependencies/tutorial001_an_py310.py!}
{!> ../../docs_src/dependencies/tutorial001_an_py310.py!}
```
////
@@ -238,7 +238,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
//// tab | Python 3.9+
```Python hl_lines="9"
{!> ../../../docs_src/dependencies/tutorial001_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial001_an_py39.py!}
```
////
@@ -246,7 +246,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
//// tab | Python 3.8+
```Python hl_lines="10"
{!> ../../../docs_src/dependencies/tutorial001_an.py!}
{!> ../../docs_src/dependencies/tutorial001_an.py!}
```
////
@@ -260,7 +260,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="6"
{!> ../../../docs_src/dependencies/tutorial001_py310.py!}
{!> ../../docs_src/dependencies/tutorial001_py310.py!}
```
////
@@ -274,7 +274,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="9"
{!> ../../../docs_src/dependencies/tutorial001.py!}
{!> ../../docs_src/dependencies/tutorial001.py!}
```
////
@@ -296,7 +296,7 @@ Jetzt können Sie Ihre Abhängigkeit mithilfe dieser Klasse deklarieren.
//// tab | Python 3.10+
```Python hl_lines="19"
{!> ../../../docs_src/dependencies/tutorial002_an_py310.py!}
{!> ../../docs_src/dependencies/tutorial002_an_py310.py!}
```
////
@@ -304,7 +304,7 @@ Jetzt können Sie Ihre Abhängigkeit mithilfe dieser Klasse deklarieren.
//// tab | Python 3.9+
```Python hl_lines="19"
{!> ../../../docs_src/dependencies/tutorial002_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial002_an_py39.py!}
```
////
@@ -312,7 +312,7 @@ Jetzt können Sie Ihre Abhängigkeit mithilfe dieser Klasse deklarieren.
//// tab | Python 3.8+
```Python hl_lines="20"
{!> ../../../docs_src/dependencies/tutorial002_an.py!}
{!> ../../docs_src/dependencies/tutorial002_an.py!}
```
////
@@ -326,7 +326,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="17"
{!> ../../../docs_src/dependencies/tutorial002_py310.py!}
{!> ../../docs_src/dependencies/tutorial002_py310.py!}
```
////
@@ -340,7 +340,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="19"
{!> ../../../docs_src/dependencies/tutorial002.py!}
{!> ../../docs_src/dependencies/tutorial002.py!}
```
////
@@ -440,7 +440,7 @@ commons = Depends(CommonQueryParams)
//// tab | Python 3.10+
```Python hl_lines="19"
{!> ../../../docs_src/dependencies/tutorial003_an_py310.py!}
{!> ../../docs_src/dependencies/tutorial003_an_py310.py!}
```
////
@@ -448,7 +448,7 @@ commons = Depends(CommonQueryParams)
//// tab | Python 3.9+
```Python hl_lines="19"
{!> ../../../docs_src/dependencies/tutorial003_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial003_an_py39.py!}
```
////
@@ -456,7 +456,7 @@ commons = Depends(CommonQueryParams)
//// tab | Python 3.8+
```Python hl_lines="20"
{!> ../../../docs_src/dependencies/tutorial003_an.py!}
{!> ../../docs_src/dependencies/tutorial003_an.py!}
```
////
@@ -470,7 +470,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="17"
{!> ../../../docs_src/dependencies/tutorial003_py310.py!}
{!> ../../docs_src/dependencies/tutorial003_py310.py!}
```
////
@@ -484,7 +484,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="19"
{!> ../../../docs_src/dependencies/tutorial003.py!}
{!> ../../docs_src/dependencies/tutorial003.py!}
```
////
@@ -578,7 +578,7 @@ Dasselbe Beispiel würde dann so aussehen:
//// tab | Python 3.10+
```Python hl_lines="19"
{!> ../../../docs_src/dependencies/tutorial004_an_py310.py!}
{!> ../../docs_src/dependencies/tutorial004_an_py310.py!}
```
////
@@ -586,7 +586,7 @@ Dasselbe Beispiel würde dann so aussehen:
//// tab | Python 3.9+
```Python hl_lines="19"
{!> ../../../docs_src/dependencies/tutorial004_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial004_an_py39.py!}
```
////
@@ -594,7 +594,7 @@ Dasselbe Beispiel würde dann so aussehen:
//// tab | Python 3.8+
```Python hl_lines="20"
{!> ../../../docs_src/dependencies/tutorial004_an.py!}
{!> ../../docs_src/dependencies/tutorial004_an.py!}
```
////
@@ -608,7 +608,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="17"
{!> ../../../docs_src/dependencies/tutorial004_py310.py!}
{!> ../../docs_src/dependencies/tutorial004_py310.py!}
```
////
@@ -622,7 +622,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="19"
{!> ../../../docs_src/dependencies/tutorial004.py!}
{!> ../../docs_src/dependencies/tutorial004.py!}
```
////

View File

@@ -17,7 +17,7 @@ Es sollte eine `list`e von `Depends()` sein:
//// tab | Python 3.9+
```Python hl_lines="19"
{!> ../../../docs_src/dependencies/tutorial006_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial006_an_py39.py!}
```
////
@@ -25,7 +25,7 @@ Es sollte eine `list`e von `Depends()` sein:
//// tab | Python 3.8+
```Python hl_lines="18"
{!> ../../../docs_src/dependencies/tutorial006_an.py!}
{!> ../../docs_src/dependencies/tutorial006_an.py!}
```
////
@@ -39,7 +39,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="17"
{!> ../../../docs_src/dependencies/tutorial006.py!}
{!> ../../docs_src/dependencies/tutorial006.py!}
```
////
@@ -75,7 +75,7 @@ Sie können Anforderungen für einen Request (wie Header) oder andere Unterabhä
//// tab | Python 3.9+
```Python hl_lines="8 13"
{!> ../../../docs_src/dependencies/tutorial006_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial006_an_py39.py!}
```
////
@@ -83,7 +83,7 @@ Sie können Anforderungen für einen Request (wie Header) oder andere Unterabhä
//// tab | Python 3.8+
```Python hl_lines="7 12"
{!> ../../../docs_src/dependencies/tutorial006_an.py!}
{!> ../../docs_src/dependencies/tutorial006_an.py!}
```
////
@@ -97,7 +97,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="6 11"
{!> ../../../docs_src/dependencies/tutorial006.py!}
{!> ../../docs_src/dependencies/tutorial006.py!}
```
////
@@ -109,7 +109,7 @@ Die Abhängigkeiten können Exceptions `raise`n, genau wie normale Abhängigkeit
//// tab | Python 3.9+
```Python hl_lines="10 15"
{!> ../../../docs_src/dependencies/tutorial006_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial006_an_py39.py!}
```
////
@@ -117,7 +117,7 @@ Die Abhängigkeiten können Exceptions `raise`n, genau wie normale Abhängigkeit
//// tab | Python 3.8+
```Python hl_lines="9 14"
{!> ../../../docs_src/dependencies/tutorial006_an.py!}
{!> ../../docs_src/dependencies/tutorial006_an.py!}
```
////
@@ -131,7 +131,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="8 13"
{!> ../../../docs_src/dependencies/tutorial006.py!}
{!> ../../docs_src/dependencies/tutorial006.py!}
```
////
@@ -145,7 +145,7 @@ Sie können also eine normale Abhängigkeit (die einen Wert zurückgibt), die Si
//// tab | Python 3.9+
```Python hl_lines="11 16"
{!> ../../../docs_src/dependencies/tutorial006_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial006_an_py39.py!}
```
////
@@ -153,7 +153,7 @@ Sie können also eine normale Abhängigkeit (die einen Wert zurückgibt), die Si
//// tab | Python 3.8+
```Python hl_lines="10 15"
{!> ../../../docs_src/dependencies/tutorial006_an.py!}
{!> ../../docs_src/dependencies/tutorial006_an.py!}
```
////
@@ -167,7 +167,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="9 14"
{!> ../../../docs_src/dependencies/tutorial006.py!}
{!> ../../docs_src/dependencies/tutorial006.py!}
```
////

View File

@@ -30,19 +30,19 @@ Sie könnten damit beispielsweise eine Datenbanksession erstellen und diese nach
Nur der Code vor und einschließlich der `yield`-Anweisung wird ausgeführt, bevor eine Response erzeugt wird:
```Python hl_lines="2-4"
{!../../../docs_src/dependencies/tutorial007.py!}
{!../../docs_src/dependencies/tutorial007.py!}
```
Der ge`yield`ete Wert ist das, was in *Pfadoperationen* und andere Abhängigkeiten eingefügt wird:
```Python hl_lines="4"
{!../../../docs_src/dependencies/tutorial007.py!}
{!../../docs_src/dependencies/tutorial007.py!}
```
Der auf die `yield`-Anweisung folgende Code wird ausgeführt, nachdem die Response gesendet wurde:
```Python hl_lines="5-6"
{!../../../docs_src/dependencies/tutorial007.py!}
{!../../docs_src/dependencies/tutorial007.py!}
```
/// tip | "Tipp"
@@ -64,7 +64,7 @@ Sie können also mit `except SomeException` diese bestimmte Exception innerhalb
Auf die gleiche Weise können Sie `finally` verwenden, um sicherzustellen, dass die Exit-Schritte ausgeführt werden, unabhängig davon, ob eine Exception geworfen wurde oder nicht.
```Python hl_lines="3 5"
{!../../../docs_src/dependencies/tutorial007.py!}
{!../../docs_src/dependencies/tutorial007.py!}
```
## Unterabhängigkeiten mit `yield`.
@@ -78,7 +78,7 @@ Beispielsweise kann `dependency_c` von `dependency_b` und `dependency_b` von `de
//// tab | Python 3.9+
```Python hl_lines="6 14 22"
{!> ../../../docs_src/dependencies/tutorial008_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial008_an_py39.py!}
```
////
@@ -86,7 +86,7 @@ Beispielsweise kann `dependency_c` von `dependency_b` und `dependency_b` von `de
//// tab | Python 3.8+
```Python hl_lines="5 13 21"
{!> ../../../docs_src/dependencies/tutorial008_an.py!}
{!> ../../docs_src/dependencies/tutorial008_an.py!}
```
////
@@ -100,7 +100,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="4 12 20"
{!> ../../../docs_src/dependencies/tutorial008.py!}
{!> ../../docs_src/dependencies/tutorial008.py!}
```
////
@@ -114,7 +114,7 @@ Und wiederum benötigt `dependency_b` den Wert von `dependency_a` (hier `dep_a`
//// tab | Python 3.9+
```Python hl_lines="18-19 26-27"
{!> ../../../docs_src/dependencies/tutorial008_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial008_an_py39.py!}
```
////
@@ -122,7 +122,7 @@ Und wiederum benötigt `dependency_b` den Wert von `dependency_a` (hier `dep_a`
//// tab | Python 3.8+
```Python hl_lines="17-18 25-26"
{!> ../../../docs_src/dependencies/tutorial008_an.py!}
{!> ../../docs_src/dependencies/tutorial008_an.py!}
```
////
@@ -136,7 +136,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="16-17 24-25"
{!> ../../../docs_src/dependencies/tutorial008.py!}
{!> ../../docs_src/dependencies/tutorial008.py!}
```
////
@@ -174,7 +174,7 @@ Aber es ist für Sie da, wenn Sie es brauchen. 🤓
//// tab | Python 3.9+
```Python hl_lines="18-22 31"
{!> ../../../docs_src/dependencies/tutorial008b_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial008b_an_py39.py!}
```
////
@@ -182,7 +182,7 @@ Aber es ist für Sie da, wenn Sie es brauchen. 🤓
//// tab | Python 3.8+
```Python hl_lines="17-21 30"
{!> ../../../docs_src/dependencies/tutorial008b_an.py!}
{!> ../../docs_src/dependencies/tutorial008b_an.py!}
```
////
@@ -196,7 +196,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="16-20 29"
{!> ../../../docs_src/dependencies/tutorial008b.py!}
{!> ../../docs_src/dependencies/tutorial008b.py!}
```
////
@@ -321,7 +321,7 @@ In Python können Sie Kontextmanager erstellen, indem Sie <a href="https://docs.
Sie können solche auch innerhalb von **FastAPI**-Abhängigkeiten mit `yield` verwenden, indem Sie `with`- oder `async with`-Anweisungen innerhalb der Abhängigkeits-Funktion verwenden:
```Python hl_lines="1-9 13"
{!../../../docs_src/dependencies/tutorial010.py!}
{!../../docs_src/dependencies/tutorial010.py!}
```
/// tip | "Tipp"

View File

@@ -9,7 +9,7 @@ In diesem Fall werden sie auf alle *Pfadoperationen* in der Anwendung angewendet
//// tab | Python 3.9+
```Python hl_lines="16"
{!> ../../../docs_src/dependencies/tutorial012_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial012_an_py39.py!}
```
////
@@ -17,7 +17,7 @@ In diesem Fall werden sie auf alle *Pfadoperationen* in der Anwendung angewendet
//// tab | Python 3.8+
```Python hl_lines="16"
{!> ../../../docs_src/dependencies/tutorial012_an.py!}
{!> ../../docs_src/dependencies/tutorial012_an.py!}
```
////
@@ -31,7 +31,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="15"
{!> ../../../docs_src/dependencies/tutorial012.py!}
{!> ../../docs_src/dependencies/tutorial012.py!}
```
////

View File

@@ -33,7 +33,7 @@ Es handelt sich einfach um eine Funktion, die die gleichen Parameter entgegennim
//// tab | Python 3.10+
```Python hl_lines="8-9"
{!> ../../../docs_src/dependencies/tutorial001_an_py310.py!}
{!> ../../docs_src/dependencies/tutorial001_an_py310.py!}
```
////
@@ -41,7 +41,7 @@ Es handelt sich einfach um eine Funktion, die die gleichen Parameter entgegennim
//// tab | Python 3.9+
```Python hl_lines="8-11"
{!> ../../../docs_src/dependencies/tutorial001_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial001_an_py39.py!}
```
////
@@ -49,7 +49,7 @@ Es handelt sich einfach um eine Funktion, die die gleichen Parameter entgegennim
//// tab | Python 3.8+
```Python hl_lines="9-12"
{!> ../../../docs_src/dependencies/tutorial001_an.py!}
{!> ../../docs_src/dependencies/tutorial001_an.py!}
```
////
@@ -63,7 +63,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="6-7"
{!> ../../../docs_src/dependencies/tutorial001_py310.py!}
{!> ../../docs_src/dependencies/tutorial001_py310.py!}
```
////
@@ -77,7 +77,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="8-11"
{!> ../../../docs_src/dependencies/tutorial001.py!}
{!> ../../docs_src/dependencies/tutorial001.py!}
```
////
@@ -115,7 +115,7 @@ Bitte [aktualisieren Sie FastAPI](../../deployment/versions.md#upgrade-der-fasta
//// tab | Python 3.10+
```Python hl_lines="3"
{!> ../../../docs_src/dependencies/tutorial001_an_py310.py!}
{!> ../../docs_src/dependencies/tutorial001_an_py310.py!}
```
////
@@ -123,7 +123,7 @@ Bitte [aktualisieren Sie FastAPI](../../deployment/versions.md#upgrade-der-fasta
//// tab | Python 3.9+
```Python hl_lines="3"
{!> ../../../docs_src/dependencies/tutorial001_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial001_an_py39.py!}
```
////
@@ -131,7 +131,7 @@ Bitte [aktualisieren Sie FastAPI](../../deployment/versions.md#upgrade-der-fasta
//// tab | Python 3.8+
```Python hl_lines="3"
{!> ../../../docs_src/dependencies/tutorial001_an.py!}
{!> ../../docs_src/dependencies/tutorial001_an.py!}
```
////
@@ -145,7 +145,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="1"
{!> ../../../docs_src/dependencies/tutorial001_py310.py!}
{!> ../../docs_src/dependencies/tutorial001_py310.py!}
```
////
@@ -159,7 +159,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="3"
{!> ../../../docs_src/dependencies/tutorial001.py!}
{!> ../../docs_src/dependencies/tutorial001.py!}
```
////
@@ -171,7 +171,7 @@ So wie auch `Body`, `Query`, usw., verwenden Sie `Depends` mit den Parametern Ih
//// tab | Python 3.10+
```Python hl_lines="13 18"
{!> ../../../docs_src/dependencies/tutorial001_an_py310.py!}
{!> ../../docs_src/dependencies/tutorial001_an_py310.py!}
```
////
@@ -179,7 +179,7 @@ So wie auch `Body`, `Query`, usw., verwenden Sie `Depends` mit den Parametern Ih
//// tab | Python 3.9+
```Python hl_lines="15 20"
{!> ../../../docs_src/dependencies/tutorial001_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial001_an_py39.py!}
```
////
@@ -187,7 +187,7 @@ So wie auch `Body`, `Query`, usw., verwenden Sie `Depends` mit den Parametern Ih
//// tab | Python 3.8+
```Python hl_lines="16 21"
{!> ../../../docs_src/dependencies/tutorial001_an.py!}
{!> ../../docs_src/dependencies/tutorial001_an.py!}
```
////
@@ -201,7 +201,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="11 16"
{!> ../../../docs_src/dependencies/tutorial001_py310.py!}
{!> ../../docs_src/dependencies/tutorial001_py310.py!}
```
////
@@ -215,7 +215,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="15 20"
{!> ../../../docs_src/dependencies/tutorial001.py!}
{!> ../../docs_src/dependencies/tutorial001.py!}
```
////
@@ -278,7 +278,7 @@ Da wir jedoch `Annotated` verwenden, können wir diesen `Annotated`-Wert in eine
//// tab | Python 3.10+
```Python hl_lines="12 16 21"
{!> ../../../docs_src/dependencies/tutorial001_02_an_py310.py!}
{!> ../../docs_src/dependencies/tutorial001_02_an_py310.py!}
```
////
@@ -286,7 +286,7 @@ Da wir jedoch `Annotated` verwenden, können wir diesen `Annotated`-Wert in eine
//// tab | Python 3.9+
```Python hl_lines="14 18 23"
{!> ../../../docs_src/dependencies/tutorial001_02_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial001_02_an_py39.py!}
```
////
@@ -294,7 +294,7 @@ Da wir jedoch `Annotated` verwenden, können wir diesen `Annotated`-Wert in eine
//// tab | Python 3.8+
```Python hl_lines="15 19 24"
{!> ../../../docs_src/dependencies/tutorial001_02_an.py!}
{!> ../../docs_src/dependencies/tutorial001_02_an.py!}
```
////

View File

@@ -13,7 +13,7 @@ Sie könnten eine erste Abhängigkeit („Dependable“) wie folgt erstellen:
//// tab | Python 3.10+
```Python hl_lines="8-9"
{!> ../../../docs_src/dependencies/tutorial005_an_py310.py!}
{!> ../../docs_src/dependencies/tutorial005_an_py310.py!}
```
////
@@ -21,7 +21,7 @@ Sie könnten eine erste Abhängigkeit („Dependable“) wie folgt erstellen:
//// tab | Python 3.9+
```Python hl_lines="8-9"
{!> ../../../docs_src/dependencies/tutorial005_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial005_an_py39.py!}
```
////
@@ -29,7 +29,7 @@ Sie könnten eine erste Abhängigkeit („Dependable“) wie folgt erstellen:
//// tab | Python 3.8+
```Python hl_lines="9-10"
{!> ../../../docs_src/dependencies/tutorial005_an.py!}
{!> ../../docs_src/dependencies/tutorial005_an.py!}
```
////
@@ -43,7 +43,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="6-7"
{!> ../../../docs_src/dependencies/tutorial005_py310.py!}
{!> ../../docs_src/dependencies/tutorial005_py310.py!}
```
////
@@ -57,7 +57,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="8-9"
{!> ../../../docs_src/dependencies/tutorial005.py!}
{!> ../../docs_src/dependencies/tutorial005.py!}
```
////
@@ -73,7 +73,7 @@ Dann können Sie eine weitere Abhängigkeitsfunktion (ein „Dependable“) erst
//// tab | Python 3.10+
```Python hl_lines="13"
{!> ../../../docs_src/dependencies/tutorial005_an_py310.py!}
{!> ../../docs_src/dependencies/tutorial005_an_py310.py!}
```
////
@@ -81,7 +81,7 @@ Dann können Sie eine weitere Abhängigkeitsfunktion (ein „Dependable“) erst
//// tab | Python 3.9+
```Python hl_lines="13"
{!> ../../../docs_src/dependencies/tutorial005_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial005_an_py39.py!}
```
////
@@ -89,7 +89,7 @@ Dann können Sie eine weitere Abhängigkeitsfunktion (ein „Dependable“) erst
//// tab | Python 3.8+
```Python hl_lines="14"
{!> ../../../docs_src/dependencies/tutorial005_an.py!}
{!> ../../docs_src/dependencies/tutorial005_an.py!}
```
////
@@ -103,7 +103,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="11"
{!> ../../../docs_src/dependencies/tutorial005_py310.py!}
{!> ../../docs_src/dependencies/tutorial005_py310.py!}
```
////
@@ -117,7 +117,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="13"
{!> ../../../docs_src/dependencies/tutorial005.py!}
{!> ../../docs_src/dependencies/tutorial005.py!}
```
////
@@ -136,7 +136,7 @@ Diese Abhängigkeit verwenden wir nun wie folgt:
//// tab | Python 3.10+
```Python hl_lines="23"
{!> ../../../docs_src/dependencies/tutorial005_an_py310.py!}
{!> ../../docs_src/dependencies/tutorial005_an_py310.py!}
```
////
@@ -144,7 +144,7 @@ Diese Abhängigkeit verwenden wir nun wie folgt:
//// tab | Python 3.9+
```Python hl_lines="23"
{!> ../../../docs_src/dependencies/tutorial005_an_py39.py!}
{!> ../../docs_src/dependencies/tutorial005_an_py39.py!}
```
////
@@ -152,7 +152,7 @@ Diese Abhängigkeit verwenden wir nun wie folgt:
//// tab | Python 3.8+
```Python hl_lines="24"
{!> ../../../docs_src/dependencies/tutorial005_an.py!}
{!> ../../docs_src/dependencies/tutorial005_an.py!}
```
////
@@ -166,7 +166,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="19"
{!> ../../../docs_src/dependencies/tutorial005_py310.py!}
{!> ../../docs_src/dependencies/tutorial005_py310.py!}
```
////
@@ -180,7 +180,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="22"
{!> ../../../docs_src/dependencies/tutorial005.py!}
{!> ../../docs_src/dependencies/tutorial005.py!}
```
////

View File

@@ -23,7 +23,7 @@ Es nimmt ein Objekt entgegen, wie etwa ein Pydantic-Modell, und gibt eine JSON-k
//// tab | Python 3.10+
```Python hl_lines="4 21"
{!> ../../../docs_src/encoder/tutorial001_py310.py!}
{!> ../../docs_src/encoder/tutorial001_py310.py!}
```
////
@@ -31,7 +31,7 @@ Es nimmt ein Objekt entgegen, wie etwa ein Pydantic-Modell, und gibt eine JSON-k
//// tab | Python 3.8+
```Python hl_lines="5 22"
{!> ../../../docs_src/encoder/tutorial001.py!}
{!> ../../docs_src/encoder/tutorial001.py!}
```
////

View File

@@ -58,7 +58,7 @@ Hier ist ein Beispiel für eine *Pfadoperation* mit Parametern, die einige der o
//// tab | Python 3.10+
```Python hl_lines="1 3 12-16"
{!> ../../../docs_src/extra_data_types/tutorial001_an_py310.py!}
{!> ../../docs_src/extra_data_types/tutorial001_an_py310.py!}
```
////
@@ -66,7 +66,7 @@ Hier ist ein Beispiel für eine *Pfadoperation* mit Parametern, die einige der o
//// tab | Python 3.9+
```Python hl_lines="1 3 12-16"
{!> ../../../docs_src/extra_data_types/tutorial001_an_py39.py!}
{!> ../../docs_src/extra_data_types/tutorial001_an_py39.py!}
```
////
@@ -74,7 +74,7 @@ Hier ist ein Beispiel für eine *Pfadoperation* mit Parametern, die einige der o
//// tab | Python 3.8+
```Python hl_lines="1 3 13-17"
{!> ../../../docs_src/extra_data_types/tutorial001_an.py!}
{!> ../../docs_src/extra_data_types/tutorial001_an.py!}
```
////
@@ -88,7 +88,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="1 2 11-15"
{!> ../../../docs_src/extra_data_types/tutorial001_py310.py!}
{!> ../../docs_src/extra_data_types/tutorial001_py310.py!}
```
////
@@ -102,7 +102,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="1 2 12-16"
{!> ../../../docs_src/extra_data_types/tutorial001.py!}
{!> ../../docs_src/extra_data_types/tutorial001.py!}
```
////
@@ -112,7 +112,7 @@ Beachten Sie, dass die Parameter innerhalb der Funktion ihren natürlichen Daten
//// tab | Python 3.10+
```Python hl_lines="18-19"
{!> ../../../docs_src/extra_data_types/tutorial001_an_py310.py!}
{!> ../../docs_src/extra_data_types/tutorial001_an_py310.py!}
```
////
@@ -120,7 +120,7 @@ Beachten Sie, dass die Parameter innerhalb der Funktion ihren natürlichen Daten
//// tab | Python 3.9+
```Python hl_lines="18-19"
{!> ../../../docs_src/extra_data_types/tutorial001_an_py39.py!}
{!> ../../docs_src/extra_data_types/tutorial001_an_py39.py!}
```
////
@@ -128,7 +128,7 @@ Beachten Sie, dass die Parameter innerhalb der Funktion ihren natürlichen Daten
//// tab | Python 3.8+
```Python hl_lines="19-20"
{!> ../../../docs_src/extra_data_types/tutorial001_an.py!}
{!> ../../docs_src/extra_data_types/tutorial001_an.py!}
```
////
@@ -142,7 +142,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="17-18"
{!> ../../../docs_src/extra_data_types/tutorial001_py310.py!}
{!> ../../docs_src/extra_data_types/tutorial001_py310.py!}
```
////
@@ -156,7 +156,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="18-19"
{!> ../../../docs_src/extra_data_types/tutorial001.py!}
{!> ../../docs_src/extra_data_types/tutorial001.py!}
```
////

View File

@@ -23,7 +23,7 @@ Hier der generelle Weg, wie die Modelle mit ihren Passwort-Feldern aussehen kön
//// tab | Python 3.10+
```Python hl_lines="7 9 14 20 22 27-28 31-33 38-39"
{!> ../../../docs_src/extra_models/tutorial001_py310.py!}
{!> ../../docs_src/extra_models/tutorial001_py310.py!}
```
////
@@ -31,7 +31,7 @@ Hier der generelle Weg, wie die Modelle mit ihren Passwort-Feldern aussehen kön
//// tab | Python 3.8+
```Python hl_lines="9 11 16 22 24 29-30 33-35 40-41"
{!> ../../../docs_src/extra_models/tutorial001.py!}
{!> ../../docs_src/extra_models/tutorial001.py!}
```
////
@@ -179,7 +179,7 @@ Auf diese Weise beschreiben wir nur noch die Unterschiede zwischen den Modellen
//// tab | Python 3.10+
```Python hl_lines="7 13-14 17-18 21-22"
{!> ../../../docs_src/extra_models/tutorial002_py310.py!}
{!> ../../docs_src/extra_models/tutorial002_py310.py!}
```
////
@@ -187,7 +187,7 @@ Auf diese Weise beschreiben wir nur noch die Unterschiede zwischen den Modellen
//// tab | Python 3.8+
```Python hl_lines="9 15-16 19-20 23-24"
{!> ../../../docs_src/extra_models/tutorial002.py!}
{!> ../../docs_src/extra_models/tutorial002.py!}
```
////
@@ -209,7 +209,7 @@ Listen Sie, wenn Sie eine <a href="https://pydantic-docs.helpmanual.io/usage/typ
//// tab | Python 3.10+
```Python hl_lines="1 14-15 18-20 33"
{!> ../../../docs_src/extra_models/tutorial003_py310.py!}
{!> ../../docs_src/extra_models/tutorial003_py310.py!}
```
////
@@ -217,7 +217,7 @@ Listen Sie, wenn Sie eine <a href="https://pydantic-docs.helpmanual.io/usage/typ
//// tab | Python 3.8+
```Python hl_lines="1 14-15 18-20 33"
{!> ../../../docs_src/extra_models/tutorial003.py!}
{!> ../../docs_src/extra_models/tutorial003.py!}
```
////
@@ -245,7 +245,7 @@ Verwenden Sie dafür Pythons Standard `typing.List` (oder nur `list` in Python 3
//// tab | Python 3.9+
```Python hl_lines="18"
{!> ../../../docs_src/extra_models/tutorial004_py39.py!}
{!> ../../docs_src/extra_models/tutorial004_py39.py!}
```
////
@@ -253,7 +253,7 @@ Verwenden Sie dafür Pythons Standard `typing.List` (oder nur `list` in Python 3
//// tab | Python 3.8+
```Python hl_lines="1 20"
{!> ../../../docs_src/extra_models/tutorial004.py!}
{!> ../../docs_src/extra_models/tutorial004.py!}
```
////
@@ -269,7 +269,7 @@ In diesem Fall können Sie `typing.Dict` verwenden (oder nur `dict` in Python 3.
//// tab | Python 3.9+
```Python hl_lines="6"
{!> ../../../docs_src/extra_models/tutorial005_py39.py!}
{!> ../../docs_src/extra_models/tutorial005_py39.py!}
```
////
@@ -277,7 +277,7 @@ In diesem Fall können Sie `typing.Dict` verwenden (oder nur `dict` in Python 3.
//// tab | Python 3.8+
```Python hl_lines="1 8"
{!> ../../../docs_src/extra_models/tutorial005.py!}
{!> ../../docs_src/extra_models/tutorial005.py!}
```
////

View File

@@ -3,7 +3,7 @@
Die einfachste FastAPI-Datei könnte wie folgt aussehen:
```Python
{!../../../docs_src/first_steps/tutorial001.py!}
{!../../docs_src/first_steps/tutorial001.py!}
```
Kopieren Sie dies in eine Datei `main.py`.
@@ -134,7 +134,7 @@ Ebenfalls können Sie es verwenden, um automatisch Code für Clients zu generier
### Schritt 1: Importieren von `FastAPI`
```Python hl_lines="1"
{!../../../docs_src/first_steps/tutorial001.py!}
{!../../docs_src/first_steps/tutorial001.py!}
```
`FastAPI` ist eine Python-Klasse, die die gesamte Funktionalität für Ihre API bereitstellt.
@@ -150,7 +150,7 @@ Sie können alle <a href="https://www.starlette.io/" class="external-link" targe
### Schritt 2: Erzeugen einer `FastAPI`-„Instanz“
```Python hl_lines="3"
{!../../../docs_src/first_steps/tutorial001.py!}
{!../../docs_src/first_steps/tutorial001.py!}
```
In diesem Beispiel ist die Variable `app` eine „Instanz“ der Klasse `FastAPI`.
@@ -172,7 +172,7 @@ $ uvicorn main:app --reload
Wenn Sie Ihre Anwendung wie folgt erstellen:
```Python hl_lines="3"
{!../../../docs_src/first_steps/tutorial002.py!}
{!../../docs_src/first_steps/tutorial002.py!}
```
Und in eine Datei `main.py` einfügen, dann würden Sie `uvicorn` wie folgt aufrufen:
@@ -251,7 +251,7 @@ Wir werden sie auch „**Operationen**“ nennen.
#### Definieren eines *Pfadoperation-Dekorators*
```Python hl_lines="6"
{!../../../docs_src/first_steps/tutorial001.py!}
{!../../docs_src/first_steps/tutorial001.py!}
```
Das `@app.get("/")` sagt **FastAPI**, dass die Funktion direkt darunter für die Bearbeitung von Anfragen zuständig ist, die an:
@@ -307,7 +307,7 @@ Das ist unsere „**Pfadoperation-Funktion**“:
* **Funktion**: ist die Funktion direkt unter dem „Dekorator“ (unter `@app.get("/")`).
```Python hl_lines="7"
{!../../../docs_src/first_steps/tutorial001.py!}
{!../../docs_src/first_steps/tutorial001.py!}
```
Dies ist eine Python-Funktion.
@@ -321,7 +321,7 @@ In diesem Fall handelt es sich um eine `async`-Funktion.
Sie könnten sie auch als normale Funktion anstelle von `async def` definieren:
```Python hl_lines="7"
{!../../../docs_src/first_steps/tutorial003.py!}
{!../../docs_src/first_steps/tutorial003.py!}
```
/// note | "Hinweis"
@@ -333,7 +333,7 @@ Wenn Sie den Unterschied nicht kennen, lesen Sie [Async: *„In Eile?“*](../as
### Schritt 5: den Inhalt zurückgeben
```Python hl_lines="8"
{!../../../docs_src/first_steps/tutorial001.py!}
{!../../docs_src/first_steps/tutorial001.py!}
```
Sie können ein `dict`, eine `list`, einzelne Werte wie `str`, `int`, usw. zurückgeben.

View File

@@ -26,7 +26,7 @@ Um HTTP-Responses mit Fehlern zum Client zurückzugeben, verwenden Sie `HTTPExce
### `HTTPException` importieren
```Python hl_lines="1"
{!../../../docs_src/handling_errors/tutorial001.py!}
{!../../docs_src/handling_errors/tutorial001.py!}
```
### Eine `HTTPException` in Ihrem Code auslösen
@@ -42,7 +42,7 @@ Der Vorteil, eine Exception auszulösen (`raise`), statt sie zurückzugeben (`re
Im folgenden Beispiel lösen wir, wenn der Client eine ID anfragt, die nicht existiert, eine Exception mit dem Statuscode `404` aus.
```Python hl_lines="11"
{!../../../docs_src/handling_errors/tutorial001.py!}
{!../../docs_src/handling_errors/tutorial001.py!}
```
### Die resultierende Response
@@ -82,7 +82,7 @@ Sie müssen das wahrscheinlich nicht direkt in ihrem Code verwenden.
Aber falls es in einem fortgeschrittenen Szenario notwendig ist, können Sie benutzerdefinierte Header wie folgt hinzufügen:
```Python hl_lines="14"
{!../../../docs_src/handling_errors/tutorial002.py!}
{!../../docs_src/handling_errors/tutorial002.py!}
```
## Benutzerdefinierte Exceptionhandler definieren
@@ -96,7 +96,7 @@ Und Sie möchten diese Exception global mit FastAPI handhaben.
Sie könnten einen benutzerdefinierten Exceptionhandler mittels `@app.exception_handler()` hinzufügen:
```Python hl_lines="5-7 13-18 24"
{!../../../docs_src/handling_errors/tutorial003.py!}
{!../../docs_src/handling_errors/tutorial003.py!}
```
Wenn Sie nun `/unicorns/yolo` anfragen, `raise`d die *Pfadoperation* eine `UnicornException`.
@@ -136,7 +136,7 @@ Um diesen zu überschreiben, importieren Sie den `RequestValidationError` und ve
Der Exceptionhandler wird einen `Request` und die Exception entgegennehmen.
```Python hl_lines="2 14-16"
{!../../../docs_src/handling_errors/tutorial004.py!}
{!../../docs_src/handling_errors/tutorial004.py!}
```
Wenn Sie nun `/items/foo` besuchen, erhalten Sie statt des Default-JSON-Errors:
@@ -189,7 +189,7 @@ Genauso können Sie den `HTTPException`-Handler überschreiben.
Zum Beispiel könnten Sie eine Klartext-Response statt JSON für diese Fehler zurückgeben wollen:
```Python hl_lines="3-4 9-11 22"
{!../../../docs_src/handling_errors/tutorial004.py!}
{!../../docs_src/handling_errors/tutorial004.py!}
```
/// note | "Technische Details"
@@ -207,7 +207,7 @@ Der `RequestValidationError` enthält den empfangenen `body` mit den ungültigen
Sie könnten diesen verwenden, während Sie Ihre Anwendung entwickeln, um den Body zu loggen und zu debuggen, ihn zum Benutzer zurückzugeben, usw.
```Python hl_lines="14"
{!../../../docs_src/handling_errors/tutorial005.py!}
{!../../docs_src/handling_errors/tutorial005.py!}
```
Jetzt versuchen Sie, einen ungültigen Artikel zu senden:
@@ -265,7 +265,7 @@ from starlette.exceptions import HTTPException as StarletteHTTPException
Wenn Sie die Exception zusammen mit denselben Default-Exceptionhandlern von **FastAPI** verwenden möchten, können Sie die Default-Exceptionhandler von `fastapi.Exception_handlers` importieren und wiederverwenden:
```Python hl_lines="2-5 15 21"
{!../../../docs_src/handling_errors/tutorial006.py!}
{!../../docs_src/handling_errors/tutorial006.py!}
```
In diesem Beispiel `print`en Sie nur den Fehler mit einer sehr ausdrucksstarken Nachricht, aber Sie sehen, worauf wir hinauswollen. Sie können mit der Exception etwas machen und dann einfach die Default-Exceptionhandler wiederverwenden.

View File

@@ -9,7 +9,7 @@ Importieren Sie zuerst `Header`:
//// tab | Python 3.10+
```Python hl_lines="3"
{!> ../../../docs_src/header_params/tutorial001_an_py310.py!}
{!> ../../docs_src/header_params/tutorial001_an_py310.py!}
```
////
@@ -17,7 +17,7 @@ Importieren Sie zuerst `Header`:
//// tab | Python 3.9+
```Python hl_lines="3"
{!> ../../../docs_src/header_params/tutorial001_an_py39.py!}
{!> ../../docs_src/header_params/tutorial001_an_py39.py!}
```
////
@@ -25,7 +25,7 @@ Importieren Sie zuerst `Header`:
//// tab | Python 3.8+
```Python hl_lines="3"
{!> ../../../docs_src/header_params/tutorial001_an.py!}
{!> ../../docs_src/header_params/tutorial001_an.py!}
```
////
@@ -39,7 +39,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="1"
{!> ../../../docs_src/header_params/tutorial001_py310.py!}
{!> ../../docs_src/header_params/tutorial001_py310.py!}
```
////
@@ -53,7 +53,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="3"
{!> ../../../docs_src/header_params/tutorial001.py!}
{!> ../../docs_src/header_params/tutorial001.py!}
```
////
@@ -67,7 +67,7 @@ Der erste Wert ist der Typ. Sie können `Header` die gehabten Extra Validierungs
//// tab | Python 3.10+
```Python hl_lines="9"
{!> ../../../docs_src/header_params/tutorial001_an_py310.py!}
{!> ../../docs_src/header_params/tutorial001_an_py310.py!}
```
////
@@ -75,7 +75,7 @@ Der erste Wert ist der Typ. Sie können `Header` die gehabten Extra Validierungs
//// tab | Python 3.9+
```Python hl_lines="9"
{!> ../../../docs_src/header_params/tutorial001_an_py39.py!}
{!> ../../docs_src/header_params/tutorial001_an_py39.py!}
```
////
@@ -83,7 +83,7 @@ Der erste Wert ist der Typ. Sie können `Header` die gehabten Extra Validierungs
//// tab | Python 3.8+
```Python hl_lines="10"
{!> ../../../docs_src/header_params/tutorial001_an.py!}
{!> ../../docs_src/header_params/tutorial001_an.py!}
```
////
@@ -97,7 +97,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7"
{!> ../../../docs_src/header_params/tutorial001_py310.py!}
{!> ../../docs_src/header_params/tutorial001_py310.py!}
```
////
@@ -111,7 +111,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="9"
{!> ../../../docs_src/header_params/tutorial001.py!}
{!> ../../docs_src/header_params/tutorial001.py!}
```
////
@@ -149,7 +149,7 @@ Wenn Sie aus irgendeinem Grund das automatische Konvertieren von Unterstrichen z
//// tab | Python 3.10+
```Python hl_lines="10"
{!> ../../../docs_src/header_params/tutorial002_an_py310.py!}
{!> ../../docs_src/header_params/tutorial002_an_py310.py!}
```
////
@@ -157,7 +157,7 @@ Wenn Sie aus irgendeinem Grund das automatische Konvertieren von Unterstrichen z
//// tab | Python 3.9+
```Python hl_lines="11"
{!> ../../../docs_src/header_params/tutorial002_an_py39.py!}
{!> ../../docs_src/header_params/tutorial002_an_py39.py!}
```
////
@@ -165,7 +165,7 @@ Wenn Sie aus irgendeinem Grund das automatische Konvertieren von Unterstrichen z
//// tab | Python 3.8+
```Python hl_lines="12"
{!> ../../../docs_src/header_params/tutorial002_an.py!}
{!> ../../docs_src/header_params/tutorial002_an.py!}
```
////
@@ -179,7 +179,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="8"
{!> ../../../docs_src/header_params/tutorial002_py310.py!}
{!> ../../docs_src/header_params/tutorial002_py310.py!}
```
////
@@ -193,7 +193,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="10"
{!> ../../../docs_src/header_params/tutorial002.py!}
{!> ../../docs_src/header_params/tutorial002.py!}
```
////
@@ -217,7 +217,7 @@ Um zum Beispiel einen Header `X-Token` zu deklarieren, der mehrmals vorkommen ka
//// tab | Python 3.10+
```Python hl_lines="9"
{!> ../../../docs_src/header_params/tutorial003_an_py310.py!}
{!> ../../docs_src/header_params/tutorial003_an_py310.py!}
```
////
@@ -225,7 +225,7 @@ Um zum Beispiel einen Header `X-Token` zu deklarieren, der mehrmals vorkommen ka
//// tab | Python 3.9+
```Python hl_lines="9"
{!> ../../../docs_src/header_params/tutorial003_an_py39.py!}
{!> ../../docs_src/header_params/tutorial003_an_py39.py!}
```
////
@@ -233,7 +233,7 @@ Um zum Beispiel einen Header `X-Token` zu deklarieren, der mehrmals vorkommen ka
//// tab | Python 3.8+
```Python hl_lines="10"
{!> ../../../docs_src/header_params/tutorial003_an.py!}
{!> ../../docs_src/header_params/tutorial003_an.py!}
```
////
@@ -247,7 +247,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7"
{!> ../../../docs_src/header_params/tutorial003_py310.py!}
{!> ../../docs_src/header_params/tutorial003_py310.py!}
```
////
@@ -261,7 +261,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="9"
{!> ../../../docs_src/header_params/tutorial003_py39.py!}
{!> ../../docs_src/header_params/tutorial003_py39.py!}
```
////
@@ -275,7 +275,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="9"
{!> ../../../docs_src/header_params/tutorial003.py!}
{!> ../../docs_src/header_params/tutorial003.py!}
```
////

View File

@@ -19,7 +19,7 @@ Sie können die folgenden Felder festlegen, welche in der OpenAPI-Spezifikation
Sie können diese wie folgt setzen:
```Python hl_lines="3-16 19-32"
{!../../../docs_src/metadata/tutorial001.py!}
{!../../docs_src/metadata/tutorial001.py!}
```
/// tip | "Tipp"
@@ -39,7 +39,7 @@ Seit OpenAPI 3.1.0 und FastAPI 0.99.0 können Sie die `license_info` auch mit ei
Zum Beispiel:
```Python hl_lines="31"
{!../../../docs_src/metadata/tutorial001_1.py!}
{!../../docs_src/metadata/tutorial001_1.py!}
```
## Metadaten für Tags
@@ -63,7 +63,7 @@ Versuchen wir das an einem Beispiel mit Tags für `users` und `items`.
Erstellen Sie Metadaten für Ihre Tags und übergeben Sie sie an den Parameter `openapi_tags`:
```Python hl_lines="3-16 18"
{!../../../docs_src/metadata/tutorial004.py!}
{!../../docs_src/metadata/tutorial004.py!}
```
Beachten Sie, dass Sie Markdown in den Beschreibungen verwenden können. Beispielsweise wird „login“ in Fettschrift (**login**) und „fancy“ in Kursivschrift (_fancy_) angezeigt.
@@ -79,7 +79,7 @@ Sie müssen nicht für alle von Ihnen verwendeten Tags Metadaten hinzufügen.
Verwenden Sie den Parameter `tags` mit Ihren *Pfadoperationen* (und `APIRouter`n), um diese verschiedenen Tags zuzuweisen:
```Python hl_lines="21 26"
{!../../../docs_src/metadata/tutorial004.py!}
{!../../docs_src/metadata/tutorial004.py!}
```
/// info
@@ -109,7 +109,7 @@ Sie können das aber mit dem Parameter `openapi_url` konfigurieren.
Um beispielsweise festzulegen, dass es unter `/api/v1/openapi.json` bereitgestellt wird:
```Python hl_lines="3"
{!../../../docs_src/metadata/tutorial002.py!}
{!../../docs_src/metadata/tutorial002.py!}
```
Wenn Sie das OpenAPI-Schema vollständig deaktivieren möchten, können Sie `openapi_url=None` festlegen, wodurch auch die Dokumentationsbenutzeroberflächen deaktiviert werden, die es verwenden.
@@ -128,5 +128,5 @@ Sie können die beiden enthaltenen Dokumentationsbenutzeroberflächen konfigurie
Um beispielsweise Swagger UI so einzustellen, dass sie unter `/documentation` bereitgestellt wird, und ReDoc zu deaktivieren:
```Python hl_lines="3"
{!../../../docs_src/metadata/tutorial003.py!}
{!../../docs_src/metadata/tutorial003.py!}
```

View File

@@ -32,7 +32,7 @@ Die Middleware-Funktion erhält:
* Sie können die `response` dann weiter modifizieren, bevor Sie sie zurückgeben.
```Python hl_lines="8-9 11 14"
{!../../../docs_src/middleware/tutorial001.py!}
{!../../docs_src/middleware/tutorial001.py!}
```
/// tip | "Tipp"
@@ -60,7 +60,7 @@ Und auch nachdem die `response` generiert wurde, bevor sie zurückgegeben wird.
Sie könnten beispielsweise einen benutzerdefinierten Header `X-Process-Time` hinzufügen, der die Zeit in Sekunden enthält, die benötigt wurde, um den Request zu verarbeiten und eine Response zu generieren:
```Python hl_lines="10 12-13"
{!../../../docs_src/middleware/tutorial001.py!}
{!../../docs_src/middleware/tutorial001.py!}
```
## Andere Middlewares

View File

@@ -19,7 +19,7 @@ Aber falls Sie sich nicht mehr erinnern, wofür jede Nummer steht, können Sie d
//// tab | Python 3.10+
```Python hl_lines="1 15"
{!> ../../../docs_src/path_operation_configuration/tutorial001_py310.py!}
{!> ../../docs_src/path_operation_configuration/tutorial001_py310.py!}
```
////
@@ -27,7 +27,7 @@ Aber falls Sie sich nicht mehr erinnern, wofür jede Nummer steht, können Sie d
//// tab | Python 3.9+
```Python hl_lines="3 17"
{!> ../../../docs_src/path_operation_configuration/tutorial001_py39.py!}
{!> ../../docs_src/path_operation_configuration/tutorial001_py39.py!}
```
////
@@ -35,7 +35,7 @@ Aber falls Sie sich nicht mehr erinnern, wofür jede Nummer steht, können Sie d
//// tab | Python 3.8+
```Python hl_lines="3 17"
{!> ../../../docs_src/path_operation_configuration/tutorial001.py!}
{!> ../../docs_src/path_operation_configuration/tutorial001.py!}
```
////
@@ -57,7 +57,7 @@ Sie können Ihrer *Pfadoperation* Tags hinzufügen, mittels des Parameters `tags
//// tab | Python 3.10+
```Python hl_lines="15 20 25"
{!> ../../../docs_src/path_operation_configuration/tutorial002_py310.py!}
{!> ../../docs_src/path_operation_configuration/tutorial002_py310.py!}
```
////
@@ -65,7 +65,7 @@ Sie können Ihrer *Pfadoperation* Tags hinzufügen, mittels des Parameters `tags
//// tab | Python 3.9+
```Python hl_lines="17 22 27"
{!> ../../../docs_src/path_operation_configuration/tutorial002_py39.py!}
{!> ../../docs_src/path_operation_configuration/tutorial002_py39.py!}
```
////
@@ -73,7 +73,7 @@ Sie können Ihrer *Pfadoperation* Tags hinzufügen, mittels des Parameters `tags
//// tab | Python 3.8+
```Python hl_lines="17 22 27"
{!> ../../../docs_src/path_operation_configuration/tutorial002.py!}
{!> ../../docs_src/path_operation_configuration/tutorial002.py!}
```
////
@@ -91,7 +91,7 @@ In diesem Fall macht es Sinn, die Tags in einem `Enum` zu speichern.
**FastAPI** unterstützt diese genauso wie einfache Strings:
```Python hl_lines="1 8-10 13 18"
{!../../../docs_src/path_operation_configuration/tutorial002b.py!}
{!../../docs_src/path_operation_configuration/tutorial002b.py!}
```
## Zusammenfassung und Beschreibung
@@ -101,7 +101,7 @@ Sie können eine Zusammenfassung (`summary`) und eine Beschreibung (`description
//// tab | Python 3.10+
```Python hl_lines="18-19"
{!> ../../../docs_src/path_operation_configuration/tutorial003_py310.py!}
{!> ../../docs_src/path_operation_configuration/tutorial003_py310.py!}
```
////
@@ -109,7 +109,7 @@ Sie können eine Zusammenfassung (`summary`) und eine Beschreibung (`description
//// tab | Python 3.9+
```Python hl_lines="20-21"
{!> ../../../docs_src/path_operation_configuration/tutorial003_py39.py!}
{!> ../../docs_src/path_operation_configuration/tutorial003_py39.py!}
```
////
@@ -117,7 +117,7 @@ Sie können eine Zusammenfassung (`summary`) und eine Beschreibung (`description
//// tab | Python 3.8+
```Python hl_lines="20-21"
{!> ../../../docs_src/path_operation_configuration/tutorial003.py!}
{!> ../../docs_src/path_operation_configuration/tutorial003.py!}
```
////
@@ -131,7 +131,7 @@ Sie können im Docstring <a href="https://en.wikipedia.org/wiki/Markdown" class=
//// tab | Python 3.10+
```Python hl_lines="17-25"
{!> ../../../docs_src/path_operation_configuration/tutorial004_py310.py!}
{!> ../../docs_src/path_operation_configuration/tutorial004_py310.py!}
```
////
@@ -139,7 +139,7 @@ Sie können im Docstring <a href="https://en.wikipedia.org/wiki/Markdown" class=
//// tab | Python 3.9+
```Python hl_lines="19-27"
{!> ../../../docs_src/path_operation_configuration/tutorial004_py39.py!}
{!> ../../docs_src/path_operation_configuration/tutorial004_py39.py!}
```
////
@@ -147,7 +147,7 @@ Sie können im Docstring <a href="https://en.wikipedia.org/wiki/Markdown" class=
//// tab | Python 3.8+
```Python hl_lines="19-27"
{!> ../../../docs_src/path_operation_configuration/tutorial004.py!}
{!> ../../docs_src/path_operation_configuration/tutorial004.py!}
```
////
@@ -163,7 +163,7 @@ Die Response können Sie mit dem Parameter `response_description` beschreiben:
//// tab | Python 3.10+
```Python hl_lines="19"
{!> ../../../docs_src/path_operation_configuration/tutorial005_py310.py!}
{!> ../../docs_src/path_operation_configuration/tutorial005_py310.py!}
```
////
@@ -171,7 +171,7 @@ Die Response können Sie mit dem Parameter `response_description` beschreiben:
//// tab | Python 3.9+
```Python hl_lines="21"
{!> ../../../docs_src/path_operation_configuration/tutorial005_py39.py!}
{!> ../../docs_src/path_operation_configuration/tutorial005_py39.py!}
```
////
@@ -179,7 +179,7 @@ Die Response können Sie mit dem Parameter `response_description` beschreiben:
//// tab | Python 3.8+
```Python hl_lines="21"
{!> ../../../docs_src/path_operation_configuration/tutorial005.py!}
{!> ../../docs_src/path_operation_configuration/tutorial005.py!}
```
////
@@ -205,7 +205,7 @@ Daher, wenn Sie keine vergeben, wird **FastAPI** automatisch eine für „Erfolg
Wenn Sie eine *Pfadoperation* als <abbr title="deprecated obsolet, veraltet: Es soll nicht mehr verwendet werden">deprecated</abbr> kennzeichnen möchten, ohne sie zu entfernen, fügen Sie den Parameter `deprecated` hinzu:
```Python hl_lines="16"
{!../../../docs_src/path_operation_configuration/tutorial006.py!}
{!../../docs_src/path_operation_configuration/tutorial006.py!}
```
Sie wird in der interaktiven Dokumentation gut sichtbar als deprecated markiert werden:

View File

@@ -9,7 +9,7 @@ Importieren Sie zuerst `Path` von `fastapi`, und importieren Sie `Annotated`.
//// tab | Python 3.10+
```Python hl_lines="1 3"
{!> ../../../docs_src/path_params_numeric_validations/tutorial001_an_py310.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial001_an_py310.py!}
```
////
@@ -17,7 +17,7 @@ Importieren Sie zuerst `Path` von `fastapi`, und importieren Sie `Annotated`.
//// tab | Python 3.9+
```Python hl_lines="1 3"
{!> ../../../docs_src/path_params_numeric_validations/tutorial001_an_py39.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial001_an_py39.py!}
```
////
@@ -25,7 +25,7 @@ Importieren Sie zuerst `Path` von `fastapi`, und importieren Sie `Annotated`.
//// tab | Python 3.8+
```Python hl_lines="3-4"
{!> ../../../docs_src/path_params_numeric_validations/tutorial001_an.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial001_an.py!}
```
////
@@ -39,7 +39,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="1"
{!> ../../../docs_src/path_params_numeric_validations/tutorial001_py310.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial001_py310.py!}
```
////
@@ -53,7 +53,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="3"
{!> ../../../docs_src/path_params_numeric_validations/tutorial001.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial001.py!}
```
////
@@ -77,7 +77,7 @@ Um zum Beispiel einen `title`-Metadaten-Wert für den Pfad-Parameter `item_id` z
//// tab | Python 3.10+
```Python hl_lines="10"
{!> ../../../docs_src/path_params_numeric_validations/tutorial001_an_py310.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial001_an_py310.py!}
```
////
@@ -85,7 +85,7 @@ Um zum Beispiel einen `title`-Metadaten-Wert für den Pfad-Parameter `item_id` z
//// tab | Python 3.9+
```Python hl_lines="10"
{!> ../../../docs_src/path_params_numeric_validations/tutorial001_an_py39.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial001_an_py39.py!}
```
////
@@ -93,7 +93,7 @@ Um zum Beispiel einen `title`-Metadaten-Wert für den Pfad-Parameter `item_id` z
//// tab | Python 3.8+
```Python hl_lines="11"
{!> ../../../docs_src/path_params_numeric_validations/tutorial001_an.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial001_an.py!}
```
////
@@ -107,7 +107,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="8"
{!> ../../../docs_src/path_params_numeric_validations/tutorial001_py310.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial001_py310.py!}
```
////
@@ -121,7 +121,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="10"
{!> ../../../docs_src/path_params_numeric_validations/tutorial001.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial001.py!}
```
////
@@ -167,7 +167,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7"
{!> ../../../docs_src/path_params_numeric_validations/tutorial002.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial002.py!}
```
////
@@ -177,7 +177,7 @@ Aber bedenken Sie, dass Sie dieses Problem nicht haben, wenn Sie `Annotated` ver
//// tab | Python 3.9+
```Python hl_lines="10"
{!> ../../../docs_src/path_params_numeric_validations/tutorial002_an_py39.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial002_an_py39.py!}
```
////
@@ -185,7 +185,7 @@ Aber bedenken Sie, dass Sie dieses Problem nicht haben, wenn Sie `Annotated` ver
//// tab | Python 3.8+
```Python hl_lines="9"
{!> ../../../docs_src/path_params_numeric_validations/tutorial002_an.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial002_an.py!}
```
////
@@ -214,7 +214,7 @@ Wenn Sie eines der folgenden Dinge tun möchten:
Python macht nichts mit diesem `*`, aber es wird wissen, dass alle folgenden Parameter als <abbr title="Keyword-Argument Schlüsselwort-Argument: Das Argument wird anhand seines Namens erkannt, nicht anhand seiner Reihenfolge in der Argumentliste">Keyword-Argumente</abbr> (Schlüssel-Wert-Paare), auch bekannt als <abbr title="Von: K-ey W-ord Arg-uments"><code>kwargs</code></abbr>, verwendet werden. Selbst wenn diese keinen Defaultwert haben.
```Python hl_lines="7"
{!../../../docs_src/path_params_numeric_validations/tutorial003.py!}
{!../../docs_src/path_params_numeric_validations/tutorial003.py!}
```
### Besser mit `Annotated`
@@ -224,7 +224,7 @@ Bedenken Sie, dass Sie, wenn Sie `Annotated` verwenden, dieses Problem nicht hab
//// tab | Python 3.9+
```Python hl_lines="10"
{!> ../../../docs_src/path_params_numeric_validations/tutorial003_an_py39.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial003_an_py39.py!}
```
////
@@ -232,7 +232,7 @@ Bedenken Sie, dass Sie, wenn Sie `Annotated` verwenden, dieses Problem nicht hab
//// tab | Python 3.8+
```Python hl_lines="9"
{!> ../../../docs_src/path_params_numeric_validations/tutorial003_an.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial003_an.py!}
```
////
@@ -245,7 +245,7 @@ Hier, mit `ge=1`, wird festgelegt, dass `item_id` eine Ganzzahl benötigt, die g
//// tab | Python 3.9+
```Python hl_lines="10"
{!> ../../../docs_src/path_params_numeric_validations/tutorial004_an_py39.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial004_an_py39.py!}
```
////
@@ -253,7 +253,7 @@ Hier, mit `ge=1`, wird festgelegt, dass `item_id` eine Ganzzahl benötigt, die g
//// tab | Python 3.8+
```Python hl_lines="9"
{!> ../../../docs_src/path_params_numeric_validations/tutorial004_an.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial004_an.py!}
```
////
@@ -267,7 +267,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="8"
{!> ../../../docs_src/path_params_numeric_validations/tutorial004.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial004.py!}
```
////
@@ -282,7 +282,7 @@ Das Gleiche trifft zu auf:
//// tab | Python 3.9+
```Python hl_lines="10"
{!> ../../../docs_src/path_params_numeric_validations/tutorial005_an_py39.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial005_an_py39.py!}
```
////
@@ -290,7 +290,7 @@ Das Gleiche trifft zu auf:
//// tab | Python 3.8+
```Python hl_lines="9"
{!> ../../../docs_src/path_params_numeric_validations/tutorial005_an.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial005_an.py!}
```
////
@@ -304,7 +304,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="9"
{!> ../../../docs_src/path_params_numeric_validations/tutorial005.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial005.py!}
```
////
@@ -322,7 +322,7 @@ Das gleiche gilt für <abbr title="less than kleiner als"><code>lt</code></a
//// tab | Python 3.9+
```Python hl_lines="13"
{!> ../../../docs_src/path_params_numeric_validations/tutorial006_an_py39.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial006_an_py39.py!}
```
////
@@ -330,7 +330,7 @@ Das gleiche gilt für <abbr title="less than kleiner als"><code>lt</code></a
//// tab | Python 3.8+
```Python hl_lines="12"
{!> ../../../docs_src/path_params_numeric_validations/tutorial006_an.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial006_an.py!}
```
////
@@ -344,7 +344,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="11"
{!> ../../../docs_src/path_params_numeric_validations/tutorial006.py!}
{!> ../../docs_src/path_params_numeric_validations/tutorial006.py!}
```
////

View File

@@ -3,7 +3,7 @@
Sie können Pfad-„Parameter“ oder -„Variablen“ mit der gleichen Syntax deklarieren, welche in Python-<abbr title="Format-String Formatierter String: Der String enthält Variablen, die mit geschweiften Klammern umschlossen sind. Solche Stellen werden durch den Wert der Variable ersetzt">Format-Strings</abbr> verwendet wird:
```Python hl_lines="6-7"
{!../../../docs_src/path_params/tutorial001.py!}
{!../../docs_src/path_params/tutorial001.py!}
```
Der Wert des Pfad-Parameters `item_id` wird Ihrer Funktion als das Argument `item_id` übergeben.
@@ -19,7 +19,7 @@ Wenn Sie dieses Beispiel ausführen und auf <a href="http://127.0.0.1:8000/items
Sie können den Typ eines Pfad-Parameters in der Argumentliste der Funktion deklarieren, mit Standard-Python-Typannotationen:
```Python hl_lines="7"
{!../../../docs_src/path_params/tutorial002.py!}
{!../../docs_src/path_params/tutorial002.py!}
```
In diesem Fall wird `item_id` als `int` deklariert, also als Ganzzahl.
@@ -124,7 +124,7 @@ Und Sie haben auch einen Pfad `/users/{user_id}`, um Daten über einen spezifisc
Weil *Pfadoperationen* in ihrer Reihenfolge ausgewertet werden, müssen Sie sicherstellen, dass der Pfad `/users/me` vor `/users/{user_id}` deklariert wurde:
```Python hl_lines="6 11"
{!../../../docs_src/path_params/tutorial003.py!}
{!../../docs_src/path_params/tutorial003.py!}
```
Ansonsten würde der Pfad für `/users/{user_id}` auch `/users/me` auswerten, und annehmen, dass ein Parameter `user_id` mit dem Wert `"me"` übergeben wurde.
@@ -132,7 +132,7 @@ Ansonsten würde der Pfad für `/users/{user_id}` auch `/users/me` auswerten, un
Sie können eine Pfadoperation auch nicht erneut definieren:
```Python hl_lines="6 11"
{!../../../docs_src/path_params/tutorial003b.py!}
{!../../docs_src/path_params/tutorial003b.py!}
```
Die erste Definition wird immer verwendet werden, da ihr Pfad zuerst übereinstimmt.
@@ -150,7 +150,7 @@ Indem Sie von `str` erben, weiß die API Dokumentation, dass die Werte des Enums
Erstellen Sie dann Klassen-Attribute mit festgelegten Werten, welches die erlaubten Werte sein werden:
```Python hl_lines="1 6-9"
{!../../../docs_src/path_params/tutorial005.py!}
{!../../docs_src/path_params/tutorial005.py!}
```
/// info
@@ -170,7 +170,7 @@ Falls Sie sich fragen, was „AlexNet“, „ResNet“ und „LeNet“ ist, das
Dann erstellen Sie einen *Pfad-Parameter*, der als Typ die gerade erstellte Enum-Klasse hat (`ModelName`):
```Python hl_lines="16"
{!../../../docs_src/path_params/tutorial005.py!}
{!../../docs_src/path_params/tutorial005.py!}
```
### Testen Sie es in der API-Dokumentation
@@ -188,7 +188,7 @@ Der *Pfad-Parameter* wird ein *<abbr title="Member Mitglied: Einer der mögl
Sie können ihn mit einem Member Ihres Enums `ModelName` vergleichen:
```Python hl_lines="17"
{!../../../docs_src/path_params/tutorial005.py!}
{!../../docs_src/path_params/tutorial005.py!}
```
#### *Enum-Wert* erhalten
@@ -196,7 +196,7 @@ Sie können ihn mit einem Member Ihres Enums `ModelName` vergleichen:
Den tatsächlichen Wert (in diesem Fall ein `str`) erhalten Sie via `model_name.value`, oder generell, `ihr_enum_member.value`:
```Python hl_lines="20"
{!../../../docs_src/path_params/tutorial005.py!}
{!../../docs_src/path_params/tutorial005.py!}
```
/// tip | "Tipp"
@@ -212,7 +212,7 @@ Sie können *Enum-Member* in ihrer *Pfadoperation* zurückgeben, sogar verschach
Diese werden zu ihren entsprechenden Werten konvertiert (in diesem Fall Strings), bevor sie zum Client übertragen werden:
```Python hl_lines="18 21 23"
{!../../../docs_src/path_params/tutorial005.py!}
{!../../docs_src/path_params/tutorial005.py!}
```
In Ihrem Client erhalten Sie eine JSON-Response, wie etwa:
@@ -253,7 +253,7 @@ In diesem Fall ist der Name des Parameters `file_path`. Der letzte Teil, `:path`
Sie verwenden das also wie folgt:
```Python hl_lines="6"
{!../../../docs_src/path_params/tutorial004.py!}
{!../../docs_src/path_params/tutorial004.py!}
```
/// tip | "Tipp"

View File

@@ -7,7 +7,7 @@ Nehmen wir als Beispiel die folgende Anwendung:
//// tab | Python 3.10+
```Python hl_lines="7"
{!> ../../../docs_src/query_params_str_validations/tutorial001_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial001_py310.py!}
```
////
@@ -15,7 +15,7 @@ Nehmen wir als Beispiel die folgende Anwendung:
//// tab | Python 3.8+
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial001.py!}
{!> ../../docs_src/query_params_str_validations/tutorial001.py!}
```
////
@@ -46,7 +46,7 @@ Importieren Sie zuerst:
In Python 3.9 oder darüber, ist `Annotated` Teil der Standardbibliothek, also können Sie es von `typing` importieren.
```Python hl_lines="1 3"
{!> ../../../docs_src/query_params_str_validations/tutorial002_an_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial002_an_py310.py!}
```
////
@@ -58,7 +58,7 @@ In Versionen unter Python 3.9 importieren Sie `Annotated` von `typing_extensions
Es wird bereits mit FastAPI installiert sein.
```Python hl_lines="3-4"
{!> ../../../docs_src/query_params_str_validations/tutorial002_an.py!}
{!> ../../docs_src/query_params_str_validations/tutorial002_an.py!}
```
////
@@ -126,7 +126,7 @@ Jetzt, da wir `Annotated` für unsere Metadaten deklariert haben, fügen Sie `Qu
//// tab | Python 3.10+
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial002_an_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial002_an_py310.py!}
```
////
@@ -134,7 +134,7 @@ Jetzt, da wir `Annotated` für unsere Metadaten deklariert haben, fügen Sie `Qu
//// tab | Python 3.8+
```Python hl_lines="10"
{!> ../../../docs_src/query_params_str_validations/tutorial002_an.py!}
{!> ../../docs_src/query_params_str_validations/tutorial002_an.py!}
```
////
@@ -164,7 +164,7 @@ So würden Sie `Query()` als Defaultwert Ihres Funktionsparameters verwenden, de
//// tab | Python 3.10+
```Python hl_lines="7"
{!> ../../../docs_src/query_params_str_validations/tutorial002_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial002_py310.py!}
```
////
@@ -172,7 +172,7 @@ So würden Sie `Query()` als Defaultwert Ihres Funktionsparameters verwenden, de
//// tab | Python 3.8+
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial002.py!}
{!> ../../docs_src/query_params_str_validations/tutorial002.py!}
```
////
@@ -278,7 +278,7 @@ Sie können auch einen Parameter `min_length` hinzufügen:
//// tab | Python 3.10+
```Python hl_lines="10"
{!> ../../../docs_src/query_params_str_validations/tutorial003_an_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial003_an_py310.py!}
```
////
@@ -286,7 +286,7 @@ Sie können auch einen Parameter `min_length` hinzufügen:
//// tab | Python 3.9+
```Python hl_lines="10"
{!> ../../../docs_src/query_params_str_validations/tutorial003_an_py39.py!}
{!> ../../docs_src/query_params_str_validations/tutorial003_an_py39.py!}
```
////
@@ -294,7 +294,7 @@ Sie können auch einen Parameter `min_length` hinzufügen:
//// tab | Python 3.8+
```Python hl_lines="11"
{!> ../../../docs_src/query_params_str_validations/tutorial003_an.py!}
{!> ../../docs_src/query_params_str_validations/tutorial003_an.py!}
```
////
@@ -308,7 +308,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7"
{!> ../../../docs_src/query_params_str_validations/tutorial003_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial003_py310.py!}
```
////
@@ -322,7 +322,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="10"
{!> ../../../docs_src/query_params_str_validations/tutorial003.py!}
{!> ../../docs_src/query_params_str_validations/tutorial003.py!}
```
////
@@ -334,7 +334,7 @@ Sie können einen <abbr title="Ein regulärer Ausdruck, auch regex oder regexp g
//// tab | Python 3.10+
```Python hl_lines="11"
{!> ../../../docs_src/query_params_str_validations/tutorial004_an_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial004_an_py310.py!}
```
////
@@ -342,7 +342,7 @@ Sie können einen <abbr title="Ein regulärer Ausdruck, auch regex oder regexp g
//// tab | Python 3.9+
```Python hl_lines="11"
{!> ../../../docs_src/query_params_str_validations/tutorial004_an_py39.py!}
{!> ../../docs_src/query_params_str_validations/tutorial004_an_py39.py!}
```
////
@@ -350,7 +350,7 @@ Sie können einen <abbr title="Ein regulärer Ausdruck, auch regex oder regexp g
//// tab | Python 3.8+
```Python hl_lines="12"
{!> ../../../docs_src/query_params_str_validations/tutorial004_an.py!}
{!> ../../docs_src/query_params_str_validations/tutorial004_an.py!}
```
////
@@ -364,7 +364,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial004_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial004_py310.py!}
```
////
@@ -378,7 +378,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="11"
{!> ../../../docs_src/query_params_str_validations/tutorial004.py!}
{!> ../../docs_src/query_params_str_validations/tutorial004.py!}
```
////
@@ -402,7 +402,7 @@ Sie könnten immer noch Code sehen, der den alten Namen verwendet:
//// tab | Python 3.10+ Pydantic v1
```Python hl_lines="11"
{!> ../../../docs_src/query_params_str_validations/tutorial004_an_py310_regex.py!}
{!> ../../docs_src/query_params_str_validations/tutorial004_an_py310_regex.py!}
```
////
@@ -418,7 +418,7 @@ Beispielsweise könnten Sie den `q` Query-Parameter so deklarieren, dass er eine
//// tab | Python 3.9+
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial005_an_py39.py!}
{!> ../../docs_src/query_params_str_validations/tutorial005_an_py39.py!}
```
////
@@ -426,7 +426,7 @@ Beispielsweise könnten Sie den `q` Query-Parameter so deklarieren, dass er eine
//// tab | Python 3.8+
```Python hl_lines="8"
{!> ../../../docs_src/query_params_str_validations/tutorial005_an.py!}
{!> ../../docs_src/query_params_str_validations/tutorial005_an.py!}
```
////
@@ -440,7 +440,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7"
{!> ../../../docs_src/query_params_str_validations/tutorial005.py!}
{!> ../../docs_src/query_params_str_validations/tutorial005.py!}
```
////
@@ -488,7 +488,7 @@ Wenn Sie einen Parameter erforderlich machen wollen, während Sie `Query` verwen
//// tab | Python 3.9+
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial006_an_py39.py!}
{!> ../../docs_src/query_params_str_validations/tutorial006_an_py39.py!}
```
////
@@ -496,7 +496,7 @@ Wenn Sie einen Parameter erforderlich machen wollen, während Sie `Query` verwen
//// tab | Python 3.8+
```Python hl_lines="8"
{!> ../../../docs_src/query_params_str_validations/tutorial006_an.py!}
{!> ../../docs_src/query_params_str_validations/tutorial006_an.py!}
```
////
@@ -510,7 +510,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7"
{!> ../../../docs_src/query_params_str_validations/tutorial006.py!}
{!> ../../docs_src/query_params_str_validations/tutorial006.py!}
```
/// tip | "Tipp"
@@ -530,7 +530,7 @@ Es gibt eine Alternative, die explizit deklariert, dass ein Wert erforderlich is
//// tab | Python 3.9+
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial006b_an_py39.py!}
{!> ../../docs_src/query_params_str_validations/tutorial006b_an_py39.py!}
```
////
@@ -538,7 +538,7 @@ Es gibt eine Alternative, die explizit deklariert, dass ein Wert erforderlich is
//// tab | Python 3.8+
```Python hl_lines="8"
{!> ../../../docs_src/query_params_str_validations/tutorial006b_an.py!}
{!> ../../docs_src/query_params_str_validations/tutorial006b_an.py!}
```
////
@@ -552,7 +552,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7"
{!> ../../../docs_src/query_params_str_validations/tutorial006b.py!}
{!> ../../docs_src/query_params_str_validations/tutorial006b.py!}
```
////
@@ -576,7 +576,7 @@ Um das zu machen, deklarieren Sie, dass `None` ein gültiger Typ ist, aber verwe
//// tab | Python 3.10+
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial006c_an_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial006c_an_py310.py!}
```
////
@@ -584,7 +584,7 @@ Um das zu machen, deklarieren Sie, dass `None` ein gültiger Typ ist, aber verwe
//// tab | Python 3.9+
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial006c_an_py39.py!}
{!> ../../docs_src/query_params_str_validations/tutorial006c_an_py39.py!}
```
////
@@ -592,7 +592,7 @@ Um das zu machen, deklarieren Sie, dass `None` ein gültiger Typ ist, aber verwe
//// tab | Python 3.8+
```Python hl_lines="10"
{!> ../../../docs_src/query_params_str_validations/tutorial006c_an.py!}
{!> ../../docs_src/query_params_str_validations/tutorial006c_an.py!}
```
////
@@ -606,7 +606,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7"
{!> ../../../docs_src/query_params_str_validations/tutorial006c_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial006c_py310.py!}
```
////
@@ -620,7 +620,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial006c.py!}
{!> ../../docs_src/query_params_str_validations/tutorial006c.py!}
```
////
@@ -646,7 +646,7 @@ Um zum Beispiel einen Query-Parameter `q` zu deklarieren, der mehrere Male in de
//// tab | Python 3.10+
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial011_an_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial011_an_py310.py!}
```
////
@@ -654,7 +654,7 @@ Um zum Beispiel einen Query-Parameter `q` zu deklarieren, der mehrere Male in de
//// tab | Python 3.9+
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial011_an_py39.py!}
{!> ../../docs_src/query_params_str_validations/tutorial011_an_py39.py!}
```
////
@@ -662,7 +662,7 @@ Um zum Beispiel einen Query-Parameter `q` zu deklarieren, der mehrere Male in de
//// tab | Python 3.8+
```Python hl_lines="10"
{!> ../../../docs_src/query_params_str_validations/tutorial011_an.py!}
{!> ../../docs_src/query_params_str_validations/tutorial011_an.py!}
```
////
@@ -676,7 +676,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7"
{!> ../../../docs_src/query_params_str_validations/tutorial011_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial011_py310.py!}
```
////
@@ -690,7 +690,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial011_py39.py!}
{!> ../../docs_src/query_params_str_validations/tutorial011_py39.py!}
```
////
@@ -704,7 +704,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial011.py!}
{!> ../../docs_src/query_params_str_validations/tutorial011.py!}
```
////
@@ -745,7 +745,7 @@ Und Sie können auch eine Default-`list`e von Werten definieren, wenn keine übe
//// tab | Python 3.9+
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial012_an_py39.py!}
{!> ../../docs_src/query_params_str_validations/tutorial012_an_py39.py!}
```
////
@@ -753,7 +753,7 @@ Und Sie können auch eine Default-`list`e von Werten definieren, wenn keine übe
//// tab | Python 3.8+
```Python hl_lines="10"
{!> ../../../docs_src/query_params_str_validations/tutorial012_an.py!}
{!> ../../docs_src/query_params_str_validations/tutorial012_an.py!}
```
////
@@ -767,7 +767,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7"
{!> ../../../docs_src/query_params_str_validations/tutorial012_py39.py!}
{!> ../../docs_src/query_params_str_validations/tutorial012_py39.py!}
```
////
@@ -781,7 +781,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial012.py!}
{!> ../../docs_src/query_params_str_validations/tutorial012.py!}
```
////
@@ -810,7 +810,7 @@ Sie können auch `list` direkt verwenden, anstelle von `List[str]` (oder `list[s
//// tab | Python 3.9+
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial013_an_py39.py!}
{!> ../../docs_src/query_params_str_validations/tutorial013_an_py39.py!}
```
////
@@ -818,7 +818,7 @@ Sie können auch `list` direkt verwenden, anstelle von `List[str]` (oder `list[s
//// tab | Python 3.8+
```Python hl_lines="8"
{!> ../../../docs_src/query_params_str_validations/tutorial013_an.py!}
{!> ../../docs_src/query_params_str_validations/tutorial013_an.py!}
```
////
@@ -832,7 +832,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7"
{!> ../../../docs_src/query_params_str_validations/tutorial013.py!}
{!> ../../docs_src/query_params_str_validations/tutorial013.py!}
```
////
@@ -864,7 +864,7 @@ Sie können einen Titel hinzufügen `title`:
//// tab | Python 3.10+
```Python hl_lines="10"
{!> ../../../docs_src/query_params_str_validations/tutorial007_an_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial007_an_py310.py!}
```
////
@@ -872,7 +872,7 @@ Sie können einen Titel hinzufügen `title`:
//// tab | Python 3.9+
```Python hl_lines="10"
{!> ../../../docs_src/query_params_str_validations/tutorial007_an_py39.py!}
{!> ../../docs_src/query_params_str_validations/tutorial007_an_py39.py!}
```
////
@@ -880,7 +880,7 @@ Sie können einen Titel hinzufügen `title`:
//// tab | Python 3.8+
```Python hl_lines="11"
{!> ../../../docs_src/query_params_str_validations/tutorial007_an.py!}
{!> ../../docs_src/query_params_str_validations/tutorial007_an.py!}
```
////
@@ -894,7 +894,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="8"
{!> ../../../docs_src/query_params_str_validations/tutorial007_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial007_py310.py!}
```
////
@@ -908,7 +908,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="10"
{!> ../../../docs_src/query_params_str_validations/tutorial007.py!}
{!> ../../docs_src/query_params_str_validations/tutorial007.py!}
```
////
@@ -918,7 +918,7 @@ Und eine Beschreibung `description`:
//// tab | Python 3.10+
```Python hl_lines="14"
{!> ../../../docs_src/query_params_str_validations/tutorial008_an_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial008_an_py310.py!}
```
////
@@ -926,7 +926,7 @@ Und eine Beschreibung `description`:
//// tab | Python 3.9+
```Python hl_lines="14"
{!> ../../../docs_src/query_params_str_validations/tutorial008_an_py39.py!}
{!> ../../docs_src/query_params_str_validations/tutorial008_an_py39.py!}
```
////
@@ -934,7 +934,7 @@ Und eine Beschreibung `description`:
//// tab | Python 3.8+
```Python hl_lines="15"
{!> ../../../docs_src/query_params_str_validations/tutorial008_an.py!}
{!> ../../docs_src/query_params_str_validations/tutorial008_an.py!}
```
////
@@ -948,7 +948,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="11"
{!> ../../../docs_src/query_params_str_validations/tutorial008_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial008_py310.py!}
```
////
@@ -962,7 +962,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="13"
{!> ../../../docs_src/query_params_str_validations/tutorial008.py!}
{!> ../../docs_src/query_params_str_validations/tutorial008.py!}
```
////
@@ -988,7 +988,7 @@ Dann können Sie einen `alias` deklarieren, und dieser Alias wird verwendet, um
//// tab | Python 3.10+
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial009_an_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial009_an_py310.py!}
```
////
@@ -996,7 +996,7 @@ Dann können Sie einen `alias` deklarieren, und dieser Alias wird verwendet, um
//// tab | Python 3.9+
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial009_an_py39.py!}
{!> ../../docs_src/query_params_str_validations/tutorial009_an_py39.py!}
```
////
@@ -1004,7 +1004,7 @@ Dann können Sie einen `alias` deklarieren, und dieser Alias wird verwendet, um
//// tab | Python 3.8+
```Python hl_lines="10"
{!> ../../../docs_src/query_params_str_validations/tutorial009_an.py!}
{!> ../../docs_src/query_params_str_validations/tutorial009_an.py!}
```
////
@@ -1018,7 +1018,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7"
{!> ../../../docs_src/query_params_str_validations/tutorial009_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial009_py310.py!}
```
////
@@ -1032,7 +1032,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="9"
{!> ../../../docs_src/query_params_str_validations/tutorial009.py!}
{!> ../../docs_src/query_params_str_validations/tutorial009.py!}
```
////
@@ -1048,7 +1048,7 @@ In diesem Fall fügen Sie den Parameter `deprecated=True` zu `Query` hinzu.
//// tab | Python 3.10+
```Python hl_lines="19"
{!> ../../../docs_src/query_params_str_validations/tutorial010_an_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial010_an_py310.py!}
```
////
@@ -1056,7 +1056,7 @@ In diesem Fall fügen Sie den Parameter `deprecated=True` zu `Query` hinzu.
//// tab | Python 3.9+
```Python hl_lines="19"
{!> ../../../docs_src/query_params_str_validations/tutorial010_an_py39.py!}
{!> ../../docs_src/query_params_str_validations/tutorial010_an_py39.py!}
```
////
@@ -1064,7 +1064,7 @@ In diesem Fall fügen Sie den Parameter `deprecated=True` zu `Query` hinzu.
//// tab | Python 3.8+
```Python hl_lines="20"
{!> ../../../docs_src/query_params_str_validations/tutorial010_an.py!}
{!> ../../docs_src/query_params_str_validations/tutorial010_an.py!}
```
////
@@ -1078,7 +1078,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="16"
{!> ../../../docs_src/query_params_str_validations/tutorial010_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial010_py310.py!}
```
////
@@ -1092,7 +1092,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="18"
{!> ../../../docs_src/query_params_str_validations/tutorial010.py!}
{!> ../../docs_src/query_params_str_validations/tutorial010.py!}
```
////
@@ -1108,7 +1108,7 @@ Um einen Query-Parameter vom generierten OpenAPI-Schema auszuschließen (und dah
//// tab | Python 3.10+
```Python hl_lines="10"
{!> ../../../docs_src/query_params_str_validations/tutorial014_an_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial014_an_py310.py!}
```
////
@@ -1116,7 +1116,7 @@ Um einen Query-Parameter vom generierten OpenAPI-Schema auszuschließen (und dah
//// tab | Python 3.9+
```Python hl_lines="10"
{!> ../../../docs_src/query_params_str_validations/tutorial014_an_py39.py!}
{!> ../../docs_src/query_params_str_validations/tutorial014_an_py39.py!}
```
////
@@ -1124,7 +1124,7 @@ Um einen Query-Parameter vom generierten OpenAPI-Schema auszuschließen (und dah
//// tab | Python 3.8+
```Python hl_lines="11"
{!> ../../../docs_src/query_params_str_validations/tutorial014_an.py!}
{!> ../../docs_src/query_params_str_validations/tutorial014_an.py!}
```
////
@@ -1138,7 +1138,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="8"
{!> ../../../docs_src/query_params_str_validations/tutorial014_py310.py!}
{!> ../../docs_src/query_params_str_validations/tutorial014_py310.py!}
```
////
@@ -1152,7 +1152,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="10"
{!> ../../../docs_src/query_params_str_validations/tutorial014.py!}
{!> ../../docs_src/query_params_str_validations/tutorial014.py!}
```
////

View File

@@ -3,7 +3,7 @@
Wenn Sie in ihrer Funktion Parameter deklarieren, die nicht Teil der Pfad-Parameter sind, dann werden diese automatisch als „Query“-Parameter interpretiert.
```Python hl_lines="9"
{!../../../docs_src/query_params/tutorial001.py!}
{!../../docs_src/query_params/tutorial001.py!}
```
Query-Parameter (Deutsch: Abfrage-Parameter) sind die Schlüssel-Wert-Paare, die nach dem `?` in einer URL aufgelistet sind, getrennt durch `&`-Zeichen.
@@ -66,7 +66,7 @@ Auf die gleiche Weise können Sie optionale Query-Parameter deklarieren, indem S
//// tab | Python 3.10+
```Python hl_lines="7"
{!> ../../../docs_src/query_params/tutorial002_py310.py!}
{!> ../../docs_src/query_params/tutorial002_py310.py!}
```
////
@@ -74,7 +74,7 @@ Auf die gleiche Weise können Sie optionale Query-Parameter deklarieren, indem S
//// tab | Python 3.8+
```Python hl_lines="9"
{!> ../../../docs_src/query_params/tutorial002.py!}
{!> ../../docs_src/query_params/tutorial002.py!}
```
////
@@ -94,7 +94,7 @@ Sie können auch `bool`-Typen deklarieren und sie werden konvertiert:
//// tab | Python 3.10+
```Python hl_lines="7"
{!> ../../../docs_src/query_params/tutorial003_py310.py!}
{!> ../../docs_src/query_params/tutorial003_py310.py!}
```
////
@@ -102,7 +102,7 @@ Sie können auch `bool`-Typen deklarieren und sie werden konvertiert:
//// tab | Python 3.8+
```Python hl_lines="9"
{!> ../../../docs_src/query_params/tutorial003.py!}
{!> ../../docs_src/query_params/tutorial003.py!}
```
////
@@ -150,7 +150,7 @@ Parameter werden anhand ihres Namens erkannt:
//// tab | Python 3.10+
```Python hl_lines="6 8"
{!> ../../../docs_src/query_params/tutorial004_py310.py!}
{!> ../../docs_src/query_params/tutorial004_py310.py!}
```
////
@@ -158,7 +158,7 @@ Parameter werden anhand ihres Namens erkannt:
//// tab | Python 3.8+
```Python hl_lines="8 10"
{!> ../../../docs_src/query_params/tutorial004.py!}
{!> ../../docs_src/query_params/tutorial004.py!}
```
////
@@ -172,7 +172,7 @@ Wenn Sie keinen spezifischen Wert haben wollen, sondern der Parameter einfach op
Aber wenn Sie wollen, dass ein Query-Parameter erforderlich ist, vergeben Sie einfach keinen Defaultwert:
```Python hl_lines="6-7"
{!../../../docs_src/query_params/tutorial005.py!}
{!../../docs_src/query_params/tutorial005.py!}
```
Hier ist `needy` ein erforderlicher Query-Parameter vom Typ `str`.
@@ -222,7 +222,7 @@ Und natürlich können Sie einige Parameter als erforderlich, einige mit Default
//// tab | Python 3.10+
```Python hl_lines="8"
{!> ../../../docs_src/query_params/tutorial006_py310.py!}
{!> ../../docs_src/query_params/tutorial006_py310.py!}
```
////
@@ -230,7 +230,7 @@ Und natürlich können Sie einige Parameter als erforderlich, einige mit Default
//// tab | Python 3.8+
```Python hl_lines="10"
{!> ../../../docs_src/query_params/tutorial006.py!}
{!> ../../docs_src/query_params/tutorial006.py!}
```
////

View File

@@ -19,7 +19,7 @@ Importieren Sie `File` und `UploadFile` von `fastapi`:
//// tab | Python 3.9+
```Python hl_lines="3"
{!> ../../../docs_src/request_files/tutorial001_an_py39.py!}
{!> ../../docs_src/request_files/tutorial001_an_py39.py!}
```
////
@@ -27,7 +27,7 @@ Importieren Sie `File` und `UploadFile` von `fastapi`:
//// tab | Python 3.8+
```Python hl_lines="1"
{!> ../../../docs_src/request_files/tutorial001_an.py!}
{!> ../../docs_src/request_files/tutorial001_an.py!}
```
////
@@ -41,7 +41,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="1"
{!> ../../../docs_src/request_files/tutorial001.py!}
{!> ../../docs_src/request_files/tutorial001.py!}
```
////
@@ -53,7 +53,7 @@ Erstellen Sie Datei-Parameter, so wie Sie es auch mit `Body` und `Form` machen w
//// tab | Python 3.9+
```Python hl_lines="9"
{!> ../../../docs_src/request_files/tutorial001_an_py39.py!}
{!> ../../docs_src/request_files/tutorial001_an_py39.py!}
```
////
@@ -61,7 +61,7 @@ Erstellen Sie Datei-Parameter, so wie Sie es auch mit `Body` und `Form` machen w
//// tab | Python 3.8+
```Python hl_lines="8"
{!> ../../../docs_src/request_files/tutorial001_an.py!}
{!> ../../docs_src/request_files/tutorial001_an.py!}
```
////
@@ -75,7 +75,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7"
{!> ../../../docs_src/request_files/tutorial001.py!}
{!> ../../docs_src/request_files/tutorial001.py!}
```
////
@@ -109,7 +109,7 @@ Definieren Sie einen Datei-Parameter mit dem Typ `UploadFile`:
//// tab | Python 3.9+
```Python hl_lines="14"
{!> ../../../docs_src/request_files/tutorial001_an_py39.py!}
{!> ../../docs_src/request_files/tutorial001_an_py39.py!}
```
////
@@ -117,7 +117,7 @@ Definieren Sie einen Datei-Parameter mit dem Typ `UploadFile`:
//// tab | Python 3.8+
```Python hl_lines="13"
{!> ../../../docs_src/request_files/tutorial001_an.py!}
{!> ../../docs_src/request_files/tutorial001_an.py!}
```
////
@@ -131,7 +131,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="12"
{!> ../../../docs_src/request_files/tutorial001.py!}
{!> ../../docs_src/request_files/tutorial001.py!}
```
////
@@ -220,7 +220,7 @@ Sie können eine Datei optional machen, indem Sie Standard-Typannotationen verwe
//// tab | Python 3.10+
```Python hl_lines="9 17"
{!> ../../../docs_src/request_files/tutorial001_02_an_py310.py!}
{!> ../../docs_src/request_files/tutorial001_02_an_py310.py!}
```
////
@@ -228,7 +228,7 @@ Sie können eine Datei optional machen, indem Sie Standard-Typannotationen verwe
//// tab | Python 3.9+
```Python hl_lines="9 17"
{!> ../../../docs_src/request_files/tutorial001_02_an_py39.py!}
{!> ../../docs_src/request_files/tutorial001_02_an_py39.py!}
```
////
@@ -236,7 +236,7 @@ Sie können eine Datei optional machen, indem Sie Standard-Typannotationen verwe
//// tab | Python 3.8+
```Python hl_lines="10 18"
{!> ../../../docs_src/request_files/tutorial001_02_an.py!}
{!> ../../docs_src/request_files/tutorial001_02_an.py!}
```
////
@@ -250,7 +250,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7 15"
{!> ../../../docs_src/request_files/tutorial001_02_py310.py!}
{!> ../../docs_src/request_files/tutorial001_02_py310.py!}
```
////
@@ -264,7 +264,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="9 17"
{!> ../../../docs_src/request_files/tutorial001_02.py!}
{!> ../../docs_src/request_files/tutorial001_02.py!}
```
////
@@ -276,7 +276,7 @@ Sie können auch `File()` zusammen mit `UploadFile` verwenden, um zum Beispiel z
//// tab | Python 3.9+
```Python hl_lines="9 15"
{!> ../../../docs_src/request_files/tutorial001_03_an_py39.py!}
{!> ../../docs_src/request_files/tutorial001_03_an_py39.py!}
```
////
@@ -284,7 +284,7 @@ Sie können auch `File()` zusammen mit `UploadFile` verwenden, um zum Beispiel z
//// tab | Python 3.8+
```Python hl_lines="8 14"
{!> ../../../docs_src/request_files/tutorial001_03_an.py!}
{!> ../../docs_src/request_files/tutorial001_03_an.py!}
```
////
@@ -298,7 +298,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7 13"
{!> ../../../docs_src/request_files/tutorial001_03.py!}
{!> ../../docs_src/request_files/tutorial001_03.py!}
```
////
@@ -314,7 +314,7 @@ Um das zu machen, deklarieren Sie eine Liste von `bytes` oder `UploadFile`s:
//// tab | Python 3.9+
```Python hl_lines="10 15"
{!> ../../../docs_src/request_files/tutorial002_an_py39.py!}
{!> ../../docs_src/request_files/tutorial002_an_py39.py!}
```
////
@@ -322,7 +322,7 @@ Um das zu machen, deklarieren Sie eine Liste von `bytes` oder `UploadFile`s:
//// tab | Python 3.8+
```Python hl_lines="11 16"
{!> ../../../docs_src/request_files/tutorial002_an.py!}
{!> ../../docs_src/request_files/tutorial002_an.py!}
```
////
@@ -336,7 +336,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="8 13"
{!> ../../../docs_src/request_files/tutorial002_py39.py!}
{!> ../../docs_src/request_files/tutorial002_py39.py!}
```
////
@@ -350,7 +350,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="10 15"
{!> ../../../docs_src/request_files/tutorial002.py!}
{!> ../../docs_src/request_files/tutorial002.py!}
```
////
@@ -372,7 +372,7 @@ Und so wie zuvor können Sie `File()` verwenden, um zusätzliche Parameter zu se
//// tab | Python 3.9+
```Python hl_lines="11 18-20"
{!> ../../../docs_src/request_files/tutorial003_an_py39.py!}
{!> ../../docs_src/request_files/tutorial003_an_py39.py!}
```
////
@@ -380,7 +380,7 @@ Und so wie zuvor können Sie `File()` verwenden, um zusätzliche Parameter zu se
//// tab | Python 3.8+
```Python hl_lines="12 19-21"
{!> ../../../docs_src/request_files/tutorial003_an.py!}
{!> ../../docs_src/request_files/tutorial003_an.py!}
```
////
@@ -394,7 +394,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="9 16"
{!> ../../../docs_src/request_files/tutorial003_py39.py!}
{!> ../../docs_src/request_files/tutorial003_py39.py!}
```
////
@@ -408,7 +408,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="11 18"
{!> ../../../docs_src/request_files/tutorial003.py!}
{!> ../../docs_src/request_files/tutorial003.py!}
```
////

View File

@@ -15,7 +15,7 @@ Z. B. `pip install python-multipart`.
//// tab | Python 3.9+
```Python hl_lines="3"
{!> ../../../docs_src/request_forms_and_files/tutorial001_an_py39.py!}
{!> ../../docs_src/request_forms_and_files/tutorial001_an_py39.py!}
```
////
@@ -23,7 +23,7 @@ Z. B. `pip install python-multipart`.
//// tab | Python 3.8+
```Python hl_lines="1"
{!> ../../../docs_src/request_forms_and_files/tutorial001_an.py!}
{!> ../../docs_src/request_forms_and_files/tutorial001_an.py!}
```
////
@@ -37,7 +37,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="1"
{!> ../../../docs_src/request_forms_and_files/tutorial001.py!}
{!> ../../docs_src/request_forms_and_files/tutorial001.py!}
```
////
@@ -49,7 +49,7 @@ Erstellen Sie Datei- und Formularparameter, so wie Sie es auch mit `Body` und `Q
//// tab | Python 3.9+
```Python hl_lines="10-12"
{!> ../../../docs_src/request_forms_and_files/tutorial001_an_py39.py!}
{!> ../../docs_src/request_forms_and_files/tutorial001_an_py39.py!}
```
////
@@ -57,7 +57,7 @@ Erstellen Sie Datei- und Formularparameter, so wie Sie es auch mit `Body` und `Q
//// tab | Python 3.8+
```Python hl_lines="9-11"
{!> ../../../docs_src/request_forms_and_files/tutorial001_an.py!}
{!> ../../docs_src/request_forms_and_files/tutorial001_an.py!}
```
////
@@ -71,7 +71,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="8"
{!> ../../../docs_src/request_forms_and_files/tutorial001.py!}
{!> ../../docs_src/request_forms_and_files/tutorial001.py!}
```
////

View File

@@ -17,7 +17,7 @@ Importieren Sie `Form` von `fastapi`:
//// tab | Python 3.9+
```Python hl_lines="3"
{!> ../../../docs_src/request_forms/tutorial001_an_py39.py!}
{!> ../../docs_src/request_forms/tutorial001_an_py39.py!}
```
////
@@ -25,7 +25,7 @@ Importieren Sie `Form` von `fastapi`:
//// tab | Python 3.8+
```Python hl_lines="1"
{!> ../../../docs_src/request_forms/tutorial001_an.py!}
{!> ../../docs_src/request_forms/tutorial001_an.py!}
```
////
@@ -39,7 +39,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="1"
{!> ../../../docs_src/request_forms/tutorial001.py!}
{!> ../../docs_src/request_forms/tutorial001.py!}
```
////
@@ -51,7 +51,7 @@ Erstellen Sie Formular-Parameter, so wie Sie es auch mit `Body` und `Query` mach
//// tab | Python 3.9+
```Python hl_lines="9"
{!> ../../../docs_src/request_forms/tutorial001_an_py39.py!}
{!> ../../docs_src/request_forms/tutorial001_an_py39.py!}
```
////
@@ -59,7 +59,7 @@ Erstellen Sie Formular-Parameter, so wie Sie es auch mit `Body` und `Query` mach
//// tab | Python 3.8+
```Python hl_lines="8"
{!> ../../../docs_src/request_forms/tutorial001_an.py!}
{!> ../../docs_src/request_forms/tutorial001_an.py!}
```
////
@@ -73,7 +73,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7"
{!> ../../../docs_src/request_forms/tutorial001.py!}
{!> ../../docs_src/request_forms/tutorial001.py!}
```
////

View File

@@ -7,7 +7,7 @@ Hierbei können Sie **Typannotationen** genauso verwenden, wie Sie es bei Werten
//// tab | Python 3.10+
```Python hl_lines="16 21"
{!> ../../../docs_src/response_model/tutorial001_01_py310.py!}
{!> ../../docs_src/response_model/tutorial001_01_py310.py!}
```
////
@@ -15,7 +15,7 @@ Hierbei können Sie **Typannotationen** genauso verwenden, wie Sie es bei Werten
//// tab | Python 3.9+
```Python hl_lines="18 23"
{!> ../../../docs_src/response_model/tutorial001_01_py39.py!}
{!> ../../docs_src/response_model/tutorial001_01_py39.py!}
```
////
@@ -23,7 +23,7 @@ Hierbei können Sie **Typannotationen** genauso verwenden, wie Sie es bei Werten
//// tab | Python 3.8+
```Python hl_lines="18 23"
{!> ../../../docs_src/response_model/tutorial001_01.py!}
{!> ../../docs_src/response_model/tutorial001_01.py!}
```
////
@@ -62,7 +62,7 @@ Sie können `response_model` in jeder möglichen *Pfadoperation* verwenden:
//// tab | Python 3.10+
```Python hl_lines="17 22 24-27"
{!> ../../../docs_src/response_model/tutorial001_py310.py!}
{!> ../../docs_src/response_model/tutorial001_py310.py!}
```
////
@@ -70,7 +70,7 @@ Sie können `response_model` in jeder möglichen *Pfadoperation* verwenden:
//// tab | Python 3.9+
```Python hl_lines="17 22 24-27"
{!> ../../../docs_src/response_model/tutorial001_py39.py!}
{!> ../../docs_src/response_model/tutorial001_py39.py!}
```
////
@@ -78,7 +78,7 @@ Sie können `response_model` in jeder möglichen *Pfadoperation* verwenden:
//// tab | Python 3.8+
```Python hl_lines="17 22 24-27"
{!> ../../../docs_src/response_model/tutorial001.py!}
{!> ../../docs_src/response_model/tutorial001.py!}
```
////
@@ -116,7 +116,7 @@ Im Folgenden deklarieren wir ein `UserIn`-Modell; es enthält ein Klartext-Passw
//// tab | Python 3.10+
```Python hl_lines="7 9"
{!> ../../../docs_src/response_model/tutorial002_py310.py!}
{!> ../../docs_src/response_model/tutorial002_py310.py!}
```
////
@@ -124,7 +124,7 @@ Im Folgenden deklarieren wir ein `UserIn`-Modell; es enthält ein Klartext-Passw
//// tab | Python 3.8+
```Python hl_lines="9 11"
{!> ../../../docs_src/response_model/tutorial002.py!}
{!> ../../docs_src/response_model/tutorial002.py!}
```
////
@@ -143,7 +143,7 @@ Wir verwenden dieses Modell, um sowohl unsere Eingabe- als auch Ausgabedaten zu
//// tab | Python 3.10+
```Python hl_lines="16"
{!> ../../../docs_src/response_model/tutorial002_py310.py!}
{!> ../../docs_src/response_model/tutorial002_py310.py!}
```
////
@@ -151,7 +151,7 @@ Wir verwenden dieses Modell, um sowohl unsere Eingabe- als auch Ausgabedaten zu
//// tab | Python 3.8+
```Python hl_lines="18"
{!> ../../../docs_src/response_model/tutorial002.py!}
{!> ../../docs_src/response_model/tutorial002.py!}
```
////
@@ -175,7 +175,7 @@ Wir können stattdessen ein Eingabemodell mit dem Klartext-Passwort, und ein Aus
//// tab | Python 3.10+
```Python hl_lines="9 11 16"
{!> ../../../docs_src/response_model/tutorial003_py310.py!}
{!> ../../docs_src/response_model/tutorial003_py310.py!}
```
////
@@ -183,7 +183,7 @@ Wir können stattdessen ein Eingabemodell mit dem Klartext-Passwort, und ein Aus
//// tab | Python 3.8+
```Python hl_lines="9 11 16"
{!> ../../../docs_src/response_model/tutorial003.py!}
{!> ../../docs_src/response_model/tutorial003.py!}
```
////
@@ -193,7 +193,7 @@ Obwohl unsere *Pfadoperation-Funktion* hier denselben `user` von der Eingabe zur
//// tab | Python 3.10+
```Python hl_lines="24"
{!> ../../../docs_src/response_model/tutorial003_py310.py!}
{!> ../../docs_src/response_model/tutorial003_py310.py!}
```
////
@@ -201,7 +201,7 @@ Obwohl unsere *Pfadoperation-Funktion* hier denselben `user` von der Eingabe zur
//// tab | Python 3.8+
```Python hl_lines="24"
{!> ../../../docs_src/response_model/tutorial003.py!}
{!> ../../docs_src/response_model/tutorial003.py!}
```
////
@@ -211,7 +211,7 @@ Obwohl unsere *Pfadoperation-Funktion* hier denselben `user` von der Eingabe zur
//// tab | Python 3.10+
```Python hl_lines="22"
{!> ../../../docs_src/response_model/tutorial003_py310.py!}
{!> ../../docs_src/response_model/tutorial003_py310.py!}
```
////
@@ -219,7 +219,7 @@ Obwohl unsere *Pfadoperation-Funktion* hier denselben `user` von der Eingabe zur
//// tab | Python 3.8+
```Python hl_lines="22"
{!> ../../../docs_src/response_model/tutorial003.py!}
{!> ../../docs_src/response_model/tutorial003.py!}
```
////
@@ -249,7 +249,7 @@ Und in solchen Fällen können wir Klassen und Vererbung verwenden, um Vorteil a
//// tab | Python 3.10+
```Python hl_lines="7-10 13-14 18"
{!> ../../../docs_src/response_model/tutorial003_01_py310.py!}
{!> ../../docs_src/response_model/tutorial003_01_py310.py!}
```
////
@@ -257,7 +257,7 @@ Und in solchen Fällen können wir Klassen und Vererbung verwenden, um Vorteil a
//// tab | Python 3.8+
```Python hl_lines="9-13 15-16 20"
{!> ../../../docs_src/response_model/tutorial003_01.py!}
{!> ../../docs_src/response_model/tutorial003_01.py!}
```
////
@@ -303,7 +303,7 @@ Es kann Fälle geben, bei denen Sie etwas zurückgeben, das kein gültiges Pydan
Der häufigste Anwendungsfall ist, wenn Sie [eine Response direkt zurückgeben, wie es später im Handbuch für fortgeschrittene Benutzer erläutert wird](../advanced/response-directly.md){.internal-link target=_blank}.
```Python hl_lines="8 10-11"
{!> ../../../docs_src/response_model/tutorial003_02.py!}
{!> ../../docs_src/response_model/tutorial003_02.py!}
```
Dieser einfache Anwendungsfall wird automatisch von FastAPI gehandhabt, weil die Annotation des Rückgabetyps die Klasse (oder eine Unterklasse von) `Response` ist.
@@ -315,7 +315,7 @@ Und Tools werden auch glücklich sein, weil sowohl `RedirectResponse` als auch `
Sie können auch eine Unterklasse von `Response` in der Typannotation verwenden.
```Python hl_lines="8-9"
{!> ../../../docs_src/response_model/tutorial003_03.py!}
{!> ../../docs_src/response_model/tutorial003_03.py!}
```
Das wird ebenfalls funktionieren, weil `RedirectResponse` eine Unterklasse von `Response` ist, und FastAPI sich um diesen einfachen Anwendungsfall automatisch kümmert.
@@ -329,7 +329,7 @@ Das gleiche wird passieren, wenn Sie eine <abbr title='Eine Union mehrerer Typen
//// tab | Python 3.10+
```Python hl_lines="8"
{!> ../../../docs_src/response_model/tutorial003_04_py310.py!}
{!> ../../docs_src/response_model/tutorial003_04_py310.py!}
```
////
@@ -337,7 +337,7 @@ Das gleiche wird passieren, wenn Sie eine <abbr title='Eine Union mehrerer Typen
//// tab | Python 3.8+
```Python hl_lines="10"
{!> ../../../docs_src/response_model/tutorial003_04.py!}
{!> ../../docs_src/response_model/tutorial003_04.py!}
```
////
@@ -355,7 +355,7 @@ In diesem Fall können Sie die Generierung des Responsemodells abschalten, indem
//// tab | Python 3.10+
```Python hl_lines="7"
{!> ../../../docs_src/response_model/tutorial003_05_py310.py!}
{!> ../../docs_src/response_model/tutorial003_05_py310.py!}
```
////
@@ -363,7 +363,7 @@ In diesem Fall können Sie die Generierung des Responsemodells abschalten, indem
//// tab | Python 3.8+
```Python hl_lines="9"
{!> ../../../docs_src/response_model/tutorial003_05.py!}
{!> ../../docs_src/response_model/tutorial003_05.py!}
```
////
@@ -377,7 +377,7 @@ Ihr Responsemodell könnte Defaultwerte haben, wie:
//// tab | Python 3.10+
```Python hl_lines="9 11-12"
{!> ../../../docs_src/response_model/tutorial004_py310.py!}
{!> ../../docs_src/response_model/tutorial004_py310.py!}
```
////
@@ -385,7 +385,7 @@ Ihr Responsemodell könnte Defaultwerte haben, wie:
//// tab | Python 3.9+
```Python hl_lines="11 13-14"
{!> ../../../docs_src/response_model/tutorial004_py39.py!}
{!> ../../docs_src/response_model/tutorial004_py39.py!}
```
////
@@ -393,7 +393,7 @@ Ihr Responsemodell könnte Defaultwerte haben, wie:
//// tab | Python 3.8+
```Python hl_lines="11 13-14"
{!> ../../../docs_src/response_model/tutorial004.py!}
{!> ../../docs_src/response_model/tutorial004.py!}
```
////
@@ -413,7 +413,7 @@ Sie können den *Pfadoperation-Dekorator*-Parameter `response_model_exclude_unse
//// tab | Python 3.10+
```Python hl_lines="22"
{!> ../../../docs_src/response_model/tutorial004_py310.py!}
{!> ../../docs_src/response_model/tutorial004_py310.py!}
```
////
@@ -421,7 +421,7 @@ Sie können den *Pfadoperation-Dekorator*-Parameter `response_model_exclude_unse
//// tab | Python 3.9+
```Python hl_lines="24"
{!> ../../../docs_src/response_model/tutorial004_py39.py!}
{!> ../../docs_src/response_model/tutorial004_py39.py!}
```
////
@@ -429,7 +429,7 @@ Sie können den *Pfadoperation-Dekorator*-Parameter `response_model_exclude_unse
//// tab | Python 3.8+
```Python hl_lines="24"
{!> ../../../docs_src/response_model/tutorial004.py!}
{!> ../../docs_src/response_model/tutorial004.py!}
```
////
@@ -532,7 +532,7 @@ Das trifft auch auf `response_model_by_alias` zu, welches ähnlich funktioniert.
//// tab | Python 3.10+
```Python hl_lines="29 35"
{!> ../../../docs_src/response_model/tutorial005_py310.py!}
{!> ../../docs_src/response_model/tutorial005_py310.py!}
```
////
@@ -540,7 +540,7 @@ Das trifft auch auf `response_model_by_alias` zu, welches ähnlich funktioniert.
//// tab | Python 3.8+
```Python hl_lines="31 37"
{!> ../../../docs_src/response_model/tutorial005.py!}
{!> ../../docs_src/response_model/tutorial005.py!}
```
////
@@ -560,7 +560,7 @@ Wenn Sie vergessen, ein `set` zu verwenden, und stattdessen eine `list`e oder ei
//// tab | Python 3.10+
```Python hl_lines="29 35"
{!> ../../../docs_src/response_model/tutorial006_py310.py!}
{!> ../../docs_src/response_model/tutorial006_py310.py!}
```
////
@@ -568,7 +568,7 @@ Wenn Sie vergessen, ein `set` zu verwenden, und stattdessen eine `list`e oder ei
//// tab | Python 3.8+
```Python hl_lines="31 37"
{!> ../../../docs_src/response_model/tutorial006.py!}
{!> ../../docs_src/response_model/tutorial006.py!}
```
////

View File

@@ -9,7 +9,7 @@ So wie ein Responsemodell, können Sie auch einen HTTP-Statuscode für die Respo
* usw.
```Python hl_lines="6"
{!../../../docs_src/response_status_code/tutorial001.py!}
{!../../docs_src/response_status_code/tutorial001.py!}
```
/// note | "Hinweis"
@@ -77,7 +77,7 @@ Um mehr über Statuscodes zu lernen, und welcher wofür verwendet wird, lesen Si
Schauen wir uns das vorherige Beispiel noch einmal an:
```Python hl_lines="6"
{!../../../docs_src/response_status_code/tutorial001.py!}
{!../../docs_src/response_status_code/tutorial001.py!}
```
`201` ist der Statuscode für „Created“ („Erzeugt“).
@@ -87,7 +87,7 @@ Aber Sie müssen sich nicht daran erinnern, welcher dieser Codes was bedeutet.
Sie können die Hilfsvariablen von `fastapi.status` verwenden.
```Python hl_lines="1 6"
{!../../../docs_src/response_status_code/tutorial002.py!}
{!../../docs_src/response_status_code/tutorial002.py!}
```
Diese sind nur eine Annehmlichkeit und enthalten dieselbe Nummer, aber auf diese Weise können Sie die Autovervollständigung Ihres Editors verwenden, um sie zu finden:

View File

@@ -11,7 +11,7 @@ Sie können `examples` („Beispiele“) für ein Pydantic-Modell deklarieren, w
//// tab | Python 3.10+ Pydantic v2
```Python hl_lines="13-24"
{!> ../../../docs_src/schema_extra_example/tutorial001_py310.py!}
{!> ../../docs_src/schema_extra_example/tutorial001_py310.py!}
```
////
@@ -19,7 +19,7 @@ Sie können `examples` („Beispiele“) für ein Pydantic-Modell deklarieren, w
//// tab | Python 3.10+ Pydantic v1
```Python hl_lines="13-23"
{!> ../../../docs_src/schema_extra_example/tutorial001_py310_pv1.py!}
{!> ../../docs_src/schema_extra_example/tutorial001_py310_pv1.py!}
```
////
@@ -27,7 +27,7 @@ Sie können `examples` („Beispiele“) für ein Pydantic-Modell deklarieren, w
//// tab | Python 3.8+ Pydantic v2
```Python hl_lines="15-26"
{!> ../../../docs_src/schema_extra_example/tutorial001.py!}
{!> ../../docs_src/schema_extra_example/tutorial001.py!}
```
////
@@ -35,7 +35,7 @@ Sie können `examples` („Beispiele“) für ein Pydantic-Modell deklarieren, w
//// tab | Python 3.8+ Pydantic v1
```Python hl_lines="15-25"
{!> ../../../docs_src/schema_extra_example/tutorial001_pv1.py!}
{!> ../../docs_src/schema_extra_example/tutorial001_pv1.py!}
```
////
@@ -83,7 +83,7 @@ Wenn Sie `Field()` mit Pydantic-Modellen verwenden, können Sie ebenfalls zusät
//// tab | Python 3.10+
```Python hl_lines="2 8-11"
{!> ../../../docs_src/schema_extra_example/tutorial002_py310.py!}
{!> ../../docs_src/schema_extra_example/tutorial002_py310.py!}
```
////
@@ -91,7 +91,7 @@ Wenn Sie `Field()` mit Pydantic-Modellen verwenden, können Sie ebenfalls zusät
//// tab | Python 3.8+
```Python hl_lines="4 10-13"
{!> ../../../docs_src/schema_extra_example/tutorial002.py!}
{!> ../../docs_src/schema_extra_example/tutorial002.py!}
```
////
@@ -117,7 +117,7 @@ Hier übergeben wir `examples`, welches ein einzelnes Beispiel für die in `Body
//// tab | Python 3.10+
```Python hl_lines="22-29"
{!> ../../../docs_src/schema_extra_example/tutorial003_an_py310.py!}
{!> ../../docs_src/schema_extra_example/tutorial003_an_py310.py!}
```
////
@@ -125,7 +125,7 @@ Hier übergeben wir `examples`, welches ein einzelnes Beispiel für die in `Body
//// tab | Python 3.9+
```Python hl_lines="22-29"
{!> ../../../docs_src/schema_extra_example/tutorial003_an_py39.py!}
{!> ../../docs_src/schema_extra_example/tutorial003_an_py39.py!}
```
////
@@ -133,7 +133,7 @@ Hier übergeben wir `examples`, welches ein einzelnes Beispiel für die in `Body
//// tab | Python 3.8+
```Python hl_lines="23-30"
{!> ../../../docs_src/schema_extra_example/tutorial003_an.py!}
{!> ../../docs_src/schema_extra_example/tutorial003_an.py!}
```
////
@@ -147,7 +147,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="18-25"
{!> ../../../docs_src/schema_extra_example/tutorial003_py310.py!}
{!> ../../docs_src/schema_extra_example/tutorial003_py310.py!}
```
////
@@ -161,7 +161,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="20-27"
{!> ../../../docs_src/schema_extra_example/tutorial003.py!}
{!> ../../docs_src/schema_extra_example/tutorial003.py!}
```
////
@@ -179,7 +179,7 @@ Sie können natürlich auch mehrere `examples` übergeben:
//// tab | Python 3.10+
```Python hl_lines="23-38"
{!> ../../../docs_src/schema_extra_example/tutorial004_an_py310.py!}
{!> ../../docs_src/schema_extra_example/tutorial004_an_py310.py!}
```
////
@@ -187,7 +187,7 @@ Sie können natürlich auch mehrere `examples` übergeben:
//// tab | Python 3.9+
```Python hl_lines="23-38"
{!> ../../../docs_src/schema_extra_example/tutorial004_an_py39.py!}
{!> ../../docs_src/schema_extra_example/tutorial004_an_py39.py!}
```
////
@@ -195,7 +195,7 @@ Sie können natürlich auch mehrere `examples` übergeben:
//// tab | Python 3.8+
```Python hl_lines="24-39"
{!> ../../../docs_src/schema_extra_example/tutorial004_an.py!}
{!> ../../docs_src/schema_extra_example/tutorial004_an.py!}
```
////
@@ -209,7 +209,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="19-34"
{!> ../../../docs_src/schema_extra_example/tutorial004_py310.py!}
{!> ../../docs_src/schema_extra_example/tutorial004_py310.py!}
```
////
@@ -223,7 +223,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="21-36"
{!> ../../../docs_src/schema_extra_example/tutorial004.py!}
{!> ../../docs_src/schema_extra_example/tutorial004.py!}
```
////
@@ -270,7 +270,7 @@ Sie können es so verwenden:
//// tab | Python 3.10+
```Python hl_lines="23-49"
{!> ../../../docs_src/schema_extra_example/tutorial005_an_py310.py!}
{!> ../../docs_src/schema_extra_example/tutorial005_an_py310.py!}
```
////
@@ -278,7 +278,7 @@ Sie können es so verwenden:
//// tab | Python 3.9+
```Python hl_lines="23-49"
{!> ../../../docs_src/schema_extra_example/tutorial005_an_py39.py!}
{!> ../../docs_src/schema_extra_example/tutorial005_an_py39.py!}
```
////
@@ -286,7 +286,7 @@ Sie können es so verwenden:
//// tab | Python 3.8+
```Python hl_lines="24-50"
{!> ../../../docs_src/schema_extra_example/tutorial005_an.py!}
{!> ../../docs_src/schema_extra_example/tutorial005_an.py!}
```
////
@@ -300,7 +300,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="19-45"
{!> ../../../docs_src/schema_extra_example/tutorial005_py310.py!}
{!> ../../docs_src/schema_extra_example/tutorial005_py310.py!}
```
////
@@ -314,7 +314,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="21-47"
{!> ../../../docs_src/schema_extra_example/tutorial005.py!}
{!> ../../docs_src/schema_extra_example/tutorial005.py!}
```
////

View File

@@ -23,7 +23,7 @@ Kopieren Sie das Beispiel in eine Datei `main.py`:
//// tab | Python 3.9+
```Python
{!> ../../../docs_src/security/tutorial001_an_py39.py!}
{!> ../../docs_src/security/tutorial001_an_py39.py!}
```
////
@@ -31,7 +31,7 @@ Kopieren Sie das Beispiel in eine Datei `main.py`:
//// tab | Python 3.8+
```Python
{!> ../../../docs_src/security/tutorial001_an.py!}
{!> ../../docs_src/security/tutorial001_an.py!}
```
////
@@ -45,7 +45,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python
{!> ../../../docs_src/security/tutorial001.py!}
{!> ../../docs_src/security/tutorial001.py!}
```
////
@@ -157,7 +157,7 @@ Wenn wir eine Instanz der Klasse `OAuth2PasswordBearer` erstellen, übergeben wi
//// tab | Python 3.9+
```Python hl_lines="8"
{!> ../../../docs_src/security/tutorial001_an_py39.py!}
{!> ../../docs_src/security/tutorial001_an_py39.py!}
```
////
@@ -165,7 +165,7 @@ Wenn wir eine Instanz der Klasse `OAuth2PasswordBearer` erstellen, übergeben wi
//// tab | Python 3.8+
```Python hl_lines="7"
{!> ../../../docs_src/security/tutorial001_an.py!}
{!> ../../docs_src/security/tutorial001_an.py!}
```
////
@@ -179,7 +179,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="6"
{!> ../../../docs_src/security/tutorial001.py!}
{!> ../../docs_src/security/tutorial001.py!}
```
////
@@ -223,7 +223,7 @@ Jetzt können Sie dieses `oauth2_scheme` als Abhängigkeit `Depends` übergeben.
//// tab | Python 3.9+
```Python hl_lines="12"
{!> ../../../docs_src/security/tutorial001_an_py39.py!}
{!> ../../docs_src/security/tutorial001_an_py39.py!}
```
////
@@ -231,7 +231,7 @@ Jetzt können Sie dieses `oauth2_scheme` als Abhängigkeit `Depends` übergeben.
//// tab | Python 3.8+
```Python hl_lines="11"
{!> ../../../docs_src/security/tutorial001_an.py!}
{!> ../../docs_src/security/tutorial001_an.py!}
```
////
@@ -245,7 +245,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="10"
{!> ../../../docs_src/security/tutorial001.py!}
{!> ../../docs_src/security/tutorial001.py!}
```
////

View File

@@ -5,7 +5,7 @@ Im vorherigen Kapitel hat das Sicherheitssystem (das auf dem Dependency Injectio
//// tab | Python 3.9+
```Python hl_lines="12"
{!> ../../../docs_src/security/tutorial001_an_py39.py!}
{!> ../../docs_src/security/tutorial001_an_py39.py!}
```
////
@@ -13,7 +13,7 @@ Im vorherigen Kapitel hat das Sicherheitssystem (das auf dem Dependency Injectio
//// tab | Python 3.8+
```Python hl_lines="11"
{!> ../../../docs_src/security/tutorial001_an.py!}
{!> ../../docs_src/security/tutorial001_an.py!}
```
////
@@ -27,7 +27,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="10"
{!> ../../../docs_src/security/tutorial001.py!}
{!> ../../docs_src/security/tutorial001.py!}
```
////
@@ -45,7 +45,7 @@ So wie wir Pydantic zum Deklarieren von Bodys verwenden, können wir es auch üb
//// tab | Python 3.10+
```Python hl_lines="5 12-16"
{!> ../../../docs_src/security/tutorial002_an_py310.py!}
{!> ../../docs_src/security/tutorial002_an_py310.py!}
```
////
@@ -53,7 +53,7 @@ So wie wir Pydantic zum Deklarieren von Bodys verwenden, können wir es auch üb
//// tab | Python 3.9+
```Python hl_lines="5 12-16"
{!> ../../../docs_src/security/tutorial002_an_py39.py!}
{!> ../../docs_src/security/tutorial002_an_py39.py!}
```
////
@@ -61,7 +61,7 @@ So wie wir Pydantic zum Deklarieren von Bodys verwenden, können wir es auch üb
//// tab | Python 3.8+
```Python hl_lines="5 13-17"
{!> ../../../docs_src/security/tutorial002_an.py!}
{!> ../../docs_src/security/tutorial002_an.py!}
```
////
@@ -75,7 +75,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="3 10-14"
{!> ../../../docs_src/security/tutorial002_py310.py!}
{!> ../../docs_src/security/tutorial002_py310.py!}
```
////
@@ -89,7 +89,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="5 12-16"
{!> ../../../docs_src/security/tutorial002.py!}
{!> ../../docs_src/security/tutorial002.py!}
```
////
@@ -107,7 +107,7 @@ So wie wir es zuvor in der *Pfadoperation* direkt gemacht haben, erhält unsere
//// tab | Python 3.10+
```Python hl_lines="25"
{!> ../../../docs_src/security/tutorial002_an_py310.py!}
{!> ../../docs_src/security/tutorial002_an_py310.py!}
```
////
@@ -115,7 +115,7 @@ So wie wir es zuvor in der *Pfadoperation* direkt gemacht haben, erhält unsere
//// tab | Python 3.9+
```Python hl_lines="25"
{!> ../../../docs_src/security/tutorial002_an_py39.py!}
{!> ../../docs_src/security/tutorial002_an_py39.py!}
```
////
@@ -123,7 +123,7 @@ So wie wir es zuvor in der *Pfadoperation* direkt gemacht haben, erhält unsere
//// tab | Python 3.8+
```Python hl_lines="26"
{!> ../../../docs_src/security/tutorial002_an.py!}
{!> ../../docs_src/security/tutorial002_an.py!}
```
////
@@ -137,7 +137,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="23"
{!> ../../../docs_src/security/tutorial002_py310.py!}
{!> ../../docs_src/security/tutorial002_py310.py!}
```
////
@@ -151,7 +151,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="25"
{!> ../../../docs_src/security/tutorial002.py!}
{!> ../../docs_src/security/tutorial002.py!}
```
////
@@ -163,7 +163,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
//// tab | Python 3.10+
```Python hl_lines="19-22 26-27"
{!> ../../../docs_src/security/tutorial002_an_py310.py!}
{!> ../../docs_src/security/tutorial002_an_py310.py!}
```
////
@@ -171,7 +171,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
//// tab | Python 3.9+
```Python hl_lines="19-22 26-27"
{!> ../../../docs_src/security/tutorial002_an_py39.py!}
{!> ../../docs_src/security/tutorial002_an_py39.py!}
```
////
@@ -179,7 +179,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
//// tab | Python 3.8+
```Python hl_lines="20-23 27-28"
{!> ../../../docs_src/security/tutorial002_an.py!}
{!> ../../docs_src/security/tutorial002_an.py!}
```
////
@@ -193,7 +193,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="17-20 24-25"
{!> ../../../docs_src/security/tutorial002_py310.py!}
{!> ../../docs_src/security/tutorial002_py310.py!}
```
////
@@ -207,7 +207,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="19-22 26-27"
{!> ../../../docs_src/security/tutorial002.py!}
{!> ../../docs_src/security/tutorial002.py!}
```
////
@@ -219,7 +219,7 @@ Und jetzt können wir wiederum `Depends` mit unserem `get_current_user` in der *
//// tab | Python 3.10+
```Python hl_lines="31"
{!> ../../../docs_src/security/tutorial002_an_py310.py!}
{!> ../../docs_src/security/tutorial002_an_py310.py!}
```
////
@@ -227,7 +227,7 @@ Und jetzt können wir wiederum `Depends` mit unserem `get_current_user` in der *
//// tab | Python 3.9+
```Python hl_lines="31"
{!> ../../../docs_src/security/tutorial002_an_py39.py!}
{!> ../../docs_src/security/tutorial002_an_py39.py!}
```
////
@@ -235,7 +235,7 @@ Und jetzt können wir wiederum `Depends` mit unserem `get_current_user` in der *
//// tab | Python 3.8+
```Python hl_lines="32"
{!> ../../../docs_src/security/tutorial002_an.py!}
{!> ../../docs_src/security/tutorial002_an.py!}
```
////
@@ -249,7 +249,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="29"
{!> ../../../docs_src/security/tutorial002_py310.py!}
{!> ../../docs_src/security/tutorial002_py310.py!}
```
////
@@ -263,7 +263,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="31"
{!> ../../../docs_src/security/tutorial002.py!}
{!> ../../docs_src/security/tutorial002.py!}
```
////
@@ -323,7 +323,7 @@ Und alle diese Tausenden von *Pfadoperationen* können nur drei Zeilen lang sein
//// tab | Python 3.10+
```Python hl_lines="30-32"
{!> ../../../docs_src/security/tutorial002_an_py310.py!}
{!> ../../docs_src/security/tutorial002_an_py310.py!}
```
////
@@ -331,7 +331,7 @@ Und alle diese Tausenden von *Pfadoperationen* können nur drei Zeilen lang sein
//// tab | Python 3.9+
```Python hl_lines="30-32"
{!> ../../../docs_src/security/tutorial002_an_py39.py!}
{!> ../../docs_src/security/tutorial002_an_py39.py!}
```
////
@@ -339,7 +339,7 @@ Und alle diese Tausenden von *Pfadoperationen* können nur drei Zeilen lang sein
//// tab | Python 3.8+
```Python hl_lines="31-33"
{!> ../../../docs_src/security/tutorial002_an.py!}
{!> ../../docs_src/security/tutorial002_an.py!}
```
////
@@ -353,7 +353,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="28-30"
{!> ../../../docs_src/security/tutorial002_py310.py!}
{!> ../../docs_src/security/tutorial002_py310.py!}
```
////
@@ -367,7 +367,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="30-32"
{!> ../../../docs_src/security/tutorial002.py!}
{!> ../../docs_src/security/tutorial002.py!}
```
////

View File

@@ -121,7 +121,7 @@ Und noch eine, um einen Benutzer zu authentifizieren und zurückzugeben.
//// tab | Python 3.10+
```Python hl_lines="7 48 55-56 59-60 69-75"
{!> ../../../docs_src/security/tutorial004_an_py310.py!}
{!> ../../docs_src/security/tutorial004_an_py310.py!}
```
////
@@ -129,7 +129,7 @@ Und noch eine, um einen Benutzer zu authentifizieren und zurückzugeben.
//// tab | Python 3.9+
```Python hl_lines="7 48 55-56 59-60 69-75"
{!> ../../../docs_src/security/tutorial004_an_py39.py!}
{!> ../../docs_src/security/tutorial004_an_py39.py!}
```
////
@@ -137,7 +137,7 @@ Und noch eine, um einen Benutzer zu authentifizieren und zurückzugeben.
//// tab | Python 3.8+
```Python hl_lines="7 49 56-57 60-61 70-76"
{!> ../../../docs_src/security/tutorial004_an.py!}
{!> ../../docs_src/security/tutorial004_an.py!}
```
////
@@ -151,7 +151,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="6 47 54-55 58-59 68-74"
{!> ../../../docs_src/security/tutorial004_py310.py!}
{!> ../../docs_src/security/tutorial004_py310.py!}
```
////
@@ -165,7 +165,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="7 48 55-56 59-60 69-75"
{!> ../../../docs_src/security/tutorial004.py!}
{!> ../../docs_src/security/tutorial004.py!}
```
////
@@ -207,7 +207,7 @@ Erstellen Sie eine Hilfsfunktion, um einen neuen Zugriffstoken zu generieren.
//// tab | Python 3.10+
```Python hl_lines="6 12-14 28-30 78-86"
{!> ../../../docs_src/security/tutorial004_an_py310.py!}
{!> ../../docs_src/security/tutorial004_an_py310.py!}
```
////
@@ -215,7 +215,7 @@ Erstellen Sie eine Hilfsfunktion, um einen neuen Zugriffstoken zu generieren.
//// tab | Python 3.9+
```Python hl_lines="6 12-14 28-30 78-86"
{!> ../../../docs_src/security/tutorial004_an_py39.py!}
{!> ../../docs_src/security/tutorial004_an_py39.py!}
```
////
@@ -223,7 +223,7 @@ Erstellen Sie eine Hilfsfunktion, um einen neuen Zugriffstoken zu generieren.
//// tab | Python 3.8+
```Python hl_lines="6 13-15 29-31 79-87"
{!> ../../../docs_src/security/tutorial004_an.py!}
{!> ../../docs_src/security/tutorial004_an.py!}
```
////
@@ -237,7 +237,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="5 11-13 27-29 77-85"
{!> ../../../docs_src/security/tutorial004_py310.py!}
{!> ../../docs_src/security/tutorial004_py310.py!}
```
////
@@ -251,7 +251,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="6 12-14 28-30 78-86"
{!> ../../../docs_src/security/tutorial004.py!}
{!> ../../docs_src/security/tutorial004.py!}
```
////
@@ -267,7 +267,7 @@ Wenn der Token ungültig ist, geben Sie sofort einen HTTP-Fehler zurück.
//// tab | Python 3.10+
```Python hl_lines="89-106"
{!> ../../../docs_src/security/tutorial004_an_py310.py!}
{!> ../../docs_src/security/tutorial004_an_py310.py!}
```
////
@@ -275,7 +275,7 @@ Wenn der Token ungültig ist, geben Sie sofort einen HTTP-Fehler zurück.
//// tab | Python 3.9+
```Python hl_lines="89-106"
{!> ../../../docs_src/security/tutorial004_an_py39.py!}
{!> ../../docs_src/security/tutorial004_an_py39.py!}
```
////
@@ -283,7 +283,7 @@ Wenn der Token ungültig ist, geben Sie sofort einen HTTP-Fehler zurück.
//// tab | Python 3.8+
```Python hl_lines="90-107"
{!> ../../../docs_src/security/tutorial004_an.py!}
{!> ../../docs_src/security/tutorial004_an.py!}
```
////
@@ -297,7 +297,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="88-105"
{!> ../../../docs_src/security/tutorial004_py310.py!}
{!> ../../docs_src/security/tutorial004_py310.py!}
```
////
@@ -311,7 +311,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="89-106"
{!> ../../../docs_src/security/tutorial004.py!}
{!> ../../docs_src/security/tutorial004.py!}
```
////
@@ -325,7 +325,7 @@ Erstellen Sie einen echten JWT-Zugriffstoken und geben Sie ihn zurück.
//// tab | Python 3.10+
```Python hl_lines="117-132"
{!> ../../../docs_src/security/tutorial004_an_py310.py!}
{!> ../../docs_src/security/tutorial004_an_py310.py!}
```
////
@@ -333,7 +333,7 @@ Erstellen Sie einen echten JWT-Zugriffstoken und geben Sie ihn zurück.
//// tab | Python 3.9+
```Python hl_lines="117-132"
{!> ../../../docs_src/security/tutorial004_an_py39.py!}
{!> ../../docs_src/security/tutorial004_an_py39.py!}
```
////
@@ -341,7 +341,7 @@ Erstellen Sie einen echten JWT-Zugriffstoken und geben Sie ihn zurück.
//// tab | Python 3.8+
```Python hl_lines="118-133"
{!> ../../../docs_src/security/tutorial004_an.py!}
{!> ../../docs_src/security/tutorial004_an.py!}
```
////
@@ -355,7 +355,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="114-129"
{!> ../../../docs_src/security/tutorial004_py310.py!}
{!> ../../docs_src/security/tutorial004_py310.py!}
```
////
@@ -369,7 +369,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="115-130"
{!> ../../../docs_src/security/tutorial004.py!}
{!> ../../docs_src/security/tutorial004.py!}
```
////

View File

@@ -55,7 +55,7 @@ Importieren Sie zunächst `OAuth2PasswordRequestForm` und verwenden Sie es als A
//// tab | Python 3.10+
```Python hl_lines="4 78"
{!> ../../../docs_src/security/tutorial003_an_py310.py!}
{!> ../../docs_src/security/tutorial003_an_py310.py!}
```
////
@@ -63,7 +63,7 @@ Importieren Sie zunächst `OAuth2PasswordRequestForm` und verwenden Sie es als A
//// tab | Python 3.9+
```Python hl_lines="4 78"
{!> ../../../docs_src/security/tutorial003_an_py39.py!}
{!> ../../docs_src/security/tutorial003_an_py39.py!}
```
////
@@ -71,7 +71,7 @@ Importieren Sie zunächst `OAuth2PasswordRequestForm` und verwenden Sie es als A
//// tab | Python 3.8+
```Python hl_lines="4 79"
{!> ../../../docs_src/security/tutorial003_an.py!}
{!> ../../docs_src/security/tutorial003_an.py!}
```
////
@@ -85,7 +85,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="2 74"
{!> ../../../docs_src/security/tutorial003_py310.py!}
{!> ../../docs_src/security/tutorial003_py310.py!}
```
////
@@ -99,7 +99,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="4 76"
{!> ../../../docs_src/security/tutorial003.py!}
{!> ../../docs_src/security/tutorial003.py!}
```
////
@@ -153,7 +153,7 @@ Für den Fehler verwenden wir die Exception `HTTPException`:
//// tab | Python 3.10+
```Python hl_lines="3 79-81"
{!> ../../../docs_src/security/tutorial003_an_py310.py!}
{!> ../../docs_src/security/tutorial003_an_py310.py!}
```
////
@@ -161,7 +161,7 @@ Für den Fehler verwenden wir die Exception `HTTPException`:
//// tab | Python 3.9+
```Python hl_lines="3 79-81"
{!> ../../../docs_src/security/tutorial003_an_py39.py!}
{!> ../../docs_src/security/tutorial003_an_py39.py!}
```
////
@@ -169,7 +169,7 @@ Für den Fehler verwenden wir die Exception `HTTPException`:
//// tab | Python 3.8+
```Python hl_lines="3 80-82"
{!> ../../../docs_src/security/tutorial003_an.py!}
{!> ../../docs_src/security/tutorial003_an.py!}
```
////
@@ -183,7 +183,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="1 75-77"
{!> ../../../docs_src/security/tutorial003_py310.py!}
{!> ../../docs_src/security/tutorial003_py310.py!}
```
////
@@ -197,7 +197,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="3 77-79"
{!> ../../../docs_src/security/tutorial003.py!}
{!> ../../docs_src/security/tutorial003.py!}
```
////
@@ -229,7 +229,7 @@ Der Dieb kann also nicht versuchen, die gleichen Passwörter in einem anderen Sy
//// tab | Python 3.10+
```Python hl_lines="82-85"
{!> ../../../docs_src/security/tutorial003_an_py310.py!}
{!> ../../docs_src/security/tutorial003_an_py310.py!}
```
////
@@ -237,7 +237,7 @@ Der Dieb kann also nicht versuchen, die gleichen Passwörter in einem anderen Sy
//// tab | Python 3.9+
```Python hl_lines="82-85"
{!> ../../../docs_src/security/tutorial003_an_py39.py!}
{!> ../../docs_src/security/tutorial003_an_py39.py!}
```
////
@@ -245,7 +245,7 @@ Der Dieb kann also nicht versuchen, die gleichen Passwörter in einem anderen Sy
//// tab | Python 3.8+
```Python hl_lines="83-86"
{!> ../../../docs_src/security/tutorial003_an.py!}
{!> ../../docs_src/security/tutorial003_an.py!}
```
////
@@ -259,7 +259,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="78-81"
{!> ../../../docs_src/security/tutorial003_py310.py!}
{!> ../../docs_src/security/tutorial003_py310.py!}
```
////
@@ -273,7 +273,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="80-83"
{!> ../../../docs_src/security/tutorial003.py!}
{!> ../../docs_src/security/tutorial003.py!}
```
////
@@ -321,7 +321,7 @@ Aber konzentrieren wir uns zunächst auf die spezifischen Details, die wir benö
//// tab | Python 3.10+
```Python hl_lines="87"
{!> ../../../docs_src/security/tutorial003_an_py310.py!}
{!> ../../docs_src/security/tutorial003_an_py310.py!}
```
////
@@ -329,7 +329,7 @@ Aber konzentrieren wir uns zunächst auf die spezifischen Details, die wir benö
//// tab | Python 3.9+
```Python hl_lines="87"
{!> ../../../docs_src/security/tutorial003_an_py39.py!}
{!> ../../docs_src/security/tutorial003_an_py39.py!}
```
////
@@ -337,7 +337,7 @@ Aber konzentrieren wir uns zunächst auf die spezifischen Details, die wir benö
//// tab | Python 3.8+
```Python hl_lines="88"
{!> ../../../docs_src/security/tutorial003_an.py!}
{!> ../../docs_src/security/tutorial003_an.py!}
```
////
@@ -351,7 +351,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="83"
{!> ../../../docs_src/security/tutorial003_py310.py!}
{!> ../../docs_src/security/tutorial003_py310.py!}
```
////
@@ -365,7 +365,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="85"
{!> ../../../docs_src/security/tutorial003.py!}
{!> ../../docs_src/security/tutorial003.py!}
```
////
@@ -397,7 +397,7 @@ In unserem Endpunkt erhalten wir also nur dann einen Benutzer, wenn der Benutzer
//// tab | Python 3.10+
```Python hl_lines="58-66 69-74 94"
{!> ../../../docs_src/security/tutorial003_an_py310.py!}
{!> ../../docs_src/security/tutorial003_an_py310.py!}
```
////
@@ -405,7 +405,7 @@ In unserem Endpunkt erhalten wir also nur dann einen Benutzer, wenn der Benutzer
//// tab | Python 3.9+
```Python hl_lines="58-66 69-74 94"
{!> ../../../docs_src/security/tutorial003_an_py39.py!}
{!> ../../docs_src/security/tutorial003_an_py39.py!}
```
////
@@ -413,7 +413,7 @@ In unserem Endpunkt erhalten wir also nur dann einen Benutzer, wenn der Benutzer
//// tab | Python 3.8+
```Python hl_lines="59-67 70-75 95"
{!> ../../../docs_src/security/tutorial003_an.py!}
{!> ../../docs_src/security/tutorial003_an.py!}
```
////
@@ -427,7 +427,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="56-64 67-70 88"
{!> ../../../docs_src/security/tutorial003_py310.py!}
{!> ../../docs_src/security/tutorial003_py310.py!}
```
////
@@ -441,7 +441,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python hl_lines="58-66 69-72 90"
{!> ../../../docs_src/security/tutorial003.py!}
{!> ../../docs_src/security/tutorial003.py!}
```
////

View File

@@ -8,7 +8,7 @@ Mit `StaticFiles` können Sie statische Dateien aus einem Verzeichnis automatisc
* „Mounten“ Sie eine `StaticFiles()`-Instanz in einem bestimmten Pfad.
```Python hl_lines="2 6"
{!../../../docs_src/static_files/tutorial001.py!}
{!../../docs_src/static_files/tutorial001.py!}
```
/// note | "Technische Details"

View File

@@ -27,7 +27,7 @@ Verwenden Sie das `TestClient`-Objekt auf die gleiche Weise wie `httpx`.
Schreiben Sie einfache `assert`-Anweisungen mit den Standard-Python-Ausdrücken, die Sie überprüfen müssen (wiederum, Standard-`pytest`).
```Python hl_lines="2 12 15-18"
{!../../../docs_src/app_testing/tutorial001.py!}
{!../../docs_src/app_testing/tutorial001.py!}
```
/// tip | "Tipp"
@@ -75,7 +75,7 @@ In der Datei `main.py` haben Sie Ihre **FastAPI**-Anwendung:
```Python
{!../../../docs_src/app_testing/main.py!}
{!../../docs_src/app_testing/main.py!}
```
### Testdatei
@@ -93,7 +93,7 @@ Dann könnten Sie eine Datei `test_main.py` mit Ihren Tests haben. Sie könnte s
Da sich diese Datei im selben Package befindet, können Sie relative Importe verwenden, um das Objekt `app` aus dem `main`-Modul (`main.py`) zu importieren:
```Python hl_lines="3"
{!../../../docs_src/app_testing/test_main.py!}
{!../../docs_src/app_testing/test_main.py!}
```
... und haben den Code für die Tests wie zuvor.
@@ -125,7 +125,7 @@ Beide *Pfadoperationen* erfordern einen `X-Token`-Header.
//// tab | Python 3.10+
```Python
{!> ../../../docs_src/app_testing/app_b_an_py310/main.py!}
{!> ../../docs_src/app_testing/app_b_an_py310/main.py!}
```
////
@@ -133,7 +133,7 @@ Beide *Pfadoperationen* erfordern einen `X-Token`-Header.
//// tab | Python 3.9+
```Python
{!> ../../../docs_src/app_testing/app_b_an_py39/main.py!}
{!> ../../docs_src/app_testing/app_b_an_py39/main.py!}
```
////
@@ -141,7 +141,7 @@ Beide *Pfadoperationen* erfordern einen `X-Token`-Header.
//// tab | Python 3.8+
```Python
{!> ../../../docs_src/app_testing/app_b_an/main.py!}
{!> ../../docs_src/app_testing/app_b_an/main.py!}
```
////
@@ -155,7 +155,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python
{!> ../../../docs_src/app_testing/app_b_py310/main.py!}
{!> ../../docs_src/app_testing/app_b_py310/main.py!}
```
////
@@ -169,7 +169,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
///
```Python
{!> ../../../docs_src/app_testing/app_b/main.py!}
{!> ../../docs_src/app_testing/app_b/main.py!}
```
////
@@ -179,7 +179,7 @@ Bevorzugen Sie die `Annotated`-Version, falls möglich.
Anschließend könnten Sie `test_main.py` mit den erweiterten Tests aktualisieren:
```Python
{!> ../../../docs_src/app_testing/app_b/test_main.py!}
{!> ../../docs_src/app_testing/app_b/test_main.py!}
```
Wenn Sie möchten, dass der Client Informationen im Request übergibt und Sie nicht wissen, wie das geht, können Sie suchen (googeln), wie es mit `httpx` gemacht wird, oder sogar, wie es mit `requests` gemacht wird, da das Design von HTTPX auf dem Design von Requests basiert.

View File

@@ -27,7 +27,7 @@
🖼, 📣 1⃣ 📨 ⏮️ 👔 📟 `404` &amp; Pydantic 🏷 `Message`, 👆 💪 ✍:
```Python hl_lines="18 22"
{!../../../docs_src/additional_responses/tutorial001.py!}
{!../../docs_src/additional_responses/tutorial001.py!}
```
/// note
@@ -178,7 +178,7 @@
🖼, 👆 💪 🚮 🌖 📻 🆎 `image/png`, 📣 👈 👆 *➡ 🛠️* 💪 📨 🎻 🎚 (⏮️ 📻 🆎 `application/json`) ⚖️ 🇩🇴 🖼:
```Python hl_lines="19-24 28"
{!../../../docs_src/additional_responses/tutorial002.py!}
{!../../docs_src/additional_responses/tutorial002.py!}
```
/// note
@@ -208,7 +208,7 @@
&amp; 📨 ⏮️ 👔 📟 `200` 👈 ⚙️ 👆 `response_model`, ✋️ 🔌 🛃 `example`:
```Python hl_lines="20-31"
{!../../../docs_src/additional_responses/tutorial003.py!}
{!../../docs_src/additional_responses/tutorial003.py!}
```
⚫️ 🔜 🌐 🌀 &amp; 🔌 👆 🗄, &amp; 🎦 🛠️ 🩺:
@@ -244,7 +244,7 @@ new_dict = {**old_dict, "new key": "new value"}
🖼:
```Python hl_lines="13-17 26"
{!../../../docs_src/additional_responses/tutorial004.py!}
{!../../docs_src/additional_responses/tutorial004.py!}
```
## 🌖 🔃 🗄 📨

View File

@@ -15,7 +15,7 @@
🏆 👈, 🗄 `JSONResponse`, &amp; 📨 👆 🎚 📤 🔗, ⚒ `status_code` 👈 👆 💚:
```Python hl_lines="4 25"
{!../../../docs_src/additional_status_codes/tutorial001.py!}
{!../../docs_src/additional_status_codes/tutorial001.py!}
```
/// warning

View File

@@ -19,7 +19,7 @@
👈, 👥 📣 👩‍🔬 `__call__`:
```Python hl_lines="10"
{!../../../docs_src/dependencies/tutorial011.py!}
{!../../docs_src/dependencies/tutorial011.py!}
```
👉 💼, 👉 `__call__` ⚫️❔ **FastAPI** 🔜 ⚙️ ✅ 🌖 🔢 &amp; 🎧-🔗, &amp; 👉 ⚫️❔ 🔜 🤙 🚶‍♀️ 💲 🔢 👆 *➡ 🛠️ 🔢* ⏪.
@@ -29,7 +29,7 @@
&amp; 🔜, 👥 💪 ⚙️ `__init__` 📣 🔢 👐 👈 👥 💪 ⚙️ "🔗" 🔗:
```Python hl_lines="7"
{!../../../docs_src/dependencies/tutorial011.py!}
{!../../docs_src/dependencies/tutorial011.py!}
```
👉 💼, **FastAPI** 🏆 🚫 ⏱ 👆 ⚖️ 💅 🔃 `__init__`, 👥 🔜 ⚙️ ⚫️ 🔗 👆 📟.
@@ -39,7 +39,7 @@
👥 💪 ✍ 👐 👉 🎓 ⏮️:
```Python hl_lines="16"
{!../../../docs_src/dependencies/tutorial011.py!}
{!../../docs_src/dependencies/tutorial011.py!}
```
&amp; 👈 🌌 👥 💪 "🔗" 👆 🔗, 👈 🔜 ✔️ `"bar"` 🔘 ⚫️, 🔢 `checker.fixed_content`.
@@ -57,7 +57,7 @@ checker(q="somequery")
...&amp; 🚶‍♀️ ⚫️❔ 👈 📨 💲 🔗 👆 *➡ 🛠️ 🔢* 🔢 `fixed_content_included`:
```Python hl_lines="20"
{!../../../docs_src/dependencies/tutorial011.py!}
{!../../docs_src/dependencies/tutorial011.py!}
```
/// tip

View File

@@ -33,13 +33,13 @@
📁 `main.py` 🔜 ✔️:
```Python
{!../../../docs_src/async_tests/main.py!}
{!../../docs_src/async_tests/main.py!}
```
📁 `test_main.py` 🔜 ✔️ 💯 `main.py`, ⚫️ 💪 👀 💖 👉 🔜:
```Python
{!../../../docs_src/async_tests/test_main.py!}
{!../../docs_src/async_tests/test_main.py!}
```
## 🏃 ⚫️
@@ -61,7 +61,7 @@ $ pytest
📑 `@pytest.mark.anyio` 💬 ✳ 👈 👉 💯 🔢 🔜 🤙 🔁:
```Python hl_lines="7"
{!../../../docs_src/async_tests/test_main.py!}
{!../../docs_src/async_tests/test_main.py!}
```
/// tip
@@ -73,7 +73,7 @@ $ pytest
⤴️ 👥 💪 ✍ `AsyncClient` ⏮️ 📱, &amp; 📨 🔁 📨 ⚫️, ⚙️ `await`.
```Python hl_lines="9-12"
{!../../../docs_src/async_tests/test_main.py!}
{!../../docs_src/async_tests/test_main.py!}
```
👉 🌓:

View File

@@ -95,7 +95,7 @@ $ uvicorn main:app --root-path /api/v1
📥 👥 ✅ ⚫️ 📧 🎦 🎯.
```Python hl_lines="8"
{!../../../docs_src/behind_a_proxy/tutorial001.py!}
{!../../docs_src/behind_a_proxy/tutorial001.py!}
```
⤴️, 🚥 👆 ▶️ Uvicorn ⏮️:
@@ -124,7 +124,7 @@ $ uvicorn main:app --root-path /api/v1
👐, 🚥 👆 🚫 ✔️ 🌌 🚚 📋 ⏸ 🎛 💖 `--root-path` ⚖️ 🌓, 👆 💪 ⚒ `root_path` 🔢 🕐❔ 🏗 👆 FastAPI 📱:
```Python hl_lines="3"
{!../../../docs_src/behind_a_proxy/tutorial002.py!}
{!../../docs_src/behind_a_proxy/tutorial002.py!}
```
🚶‍♀️ `root_path` `FastAPI` 🔜 🌓 🚶‍♀️ `--root-path` 📋 ⏸ 🎛 Uvicorn ⚖️ Hypercorn.
@@ -306,7 +306,7 @@ $ uvicorn main:app --root-path /api/v1
🖼:
```Python hl_lines="4-7"
{!../../../docs_src/behind_a_proxy/tutorial003.py!}
{!../../docs_src/behind_a_proxy/tutorial003.py!}
```
🔜 🏗 🗄 🔗 💖:
@@ -355,7 +355,7 @@ $ uvicorn main:app --root-path /api/v1
🚥 👆 🚫 💚 **FastAPI** 🔌 🏧 💽 ⚙️ `root_path`, 👆 💪 ⚙️ 🔢 `root_path_in_servers=False`:
```Python hl_lines="9"
{!../../../docs_src/behind_a_proxy/tutorial004.py!}
{!../../docs_src/behind_a_proxy/tutorial004.py!}
```
&amp; ⤴️ ⚫️ 🏆 🚫 🔌 ⚫️ 🗄 🔗.

View File

@@ -31,7 +31,7 @@
✋️ 🚥 👆 🎯 👈 🎚 👈 👆 🛬 **🎻 ⏮️ 🎻**, 👆 💪 🚶‍♀️ ⚫️ 🔗 📨 🎓 &amp; ❎ 🌥 👈 FastAPI 🔜 ✔️ 🚶‍♀️ 👆 📨 🎚 🔘 `jsonable_encoder` ⏭ 🚶‍♀️ ⚫️ 📨 🎓.
```Python hl_lines="2 7"
{!../../../docs_src/custom_response/tutorial001b.py!}
{!../../docs_src/custom_response/tutorial001b.py!}
```
/// info
@@ -58,7 +58,7 @@
* 🚶‍♀️ `HTMLResponse` 🔢 `response_class` 👆 *➡ 🛠️ 👨‍🎨*.
```Python hl_lines="2 7"
{!../../../docs_src/custom_response/tutorial002.py!}
{!../../docs_src/custom_response/tutorial002.py!}
```
/// info
@@ -78,7 +78,7 @@
🎏 🖼 ⚪️➡️ 🔛, 🛬 `HTMLResponse`, 💪 👀 💖:
```Python hl_lines="2 7 19"
{!../../../docs_src/custom_response/tutorial003.py!}
{!../../docs_src/custom_response/tutorial003.py!}
```
/// warning
@@ -104,7 +104,7 @@
🖼, ⚫️ 💪 🕳 💖:
```Python hl_lines="7 21 23"
{!../../../docs_src/custom_response/tutorial004.py!}
{!../../docs_src/custom_response/tutorial004.py!}
```
👉 🖼, 🔢 `generate_html_response()` ⏪ 🏗 &amp; 📨 `Response` ↩️ 🛬 🕸 `str`.
@@ -145,7 +145,7 @@
FastAPI (🤙 💃) 🔜 🔁 🔌 🎚-📐 🎚. ⚫️ 🔜 🔌 🎚-🆎 🎚, ⚓️ 🔛 = &amp; 🔁 = ✍ 🆎.
```Python hl_lines="1 18"
{!../../../docs_src/response_directly/tutorial002.py!}
{!../../docs_src/response_directly/tutorial002.py!}
```
### `HTMLResponse`
@@ -157,7 +157,7 @@ FastAPI (🤙 💃) 🔜 🔁 🔌 🎚-📐 🎚. ⚫️ 🔜 🔌 🎚-🆎
✊ ✍ ⚖️ 🔢 &amp; 📨 ✅ ✍ 📨.
```Python hl_lines="2 7 9"
{!../../../docs_src/custom_response/tutorial005.py!}
{!../../docs_src/custom_response/tutorial005.py!}
```
### `JSONResponse`
@@ -181,7 +181,7 @@ FastAPI (🤙 💃) 🔜 🔁 🔌 🎚-📐 🎚. ⚫️ 🔜 🔌 🎚-🆎
///
```Python hl_lines="2 7"
{!../../../docs_src/custom_response/tutorial001.py!}
{!../../docs_src/custom_response/tutorial001.py!}
```
/// tip
@@ -197,7 +197,7 @@ FastAPI (🤙 💃) 🔜 🔁 🔌 🎚-📐 🎚. ⚫️ 🔜 🔌 🎚-🆎
👆 💪 📨 `RedirectResponse` 🔗:
```Python hl_lines="2 9"
{!../../../docs_src/custom_response/tutorial006.py!}
{!../../docs_src/custom_response/tutorial006.py!}
```
---
@@ -206,7 +206,7 @@ FastAPI (🤙 💃) 🔜 🔁 🔌 🎚-📐 🎚. ⚫️ 🔜 🔌 🎚-🆎
```Python hl_lines="2 7 9"
{!../../../docs_src/custom_response/tutorial006b.py!}
{!../../docs_src/custom_response/tutorial006b.py!}
```
🚥 👆 👈, ⤴️ 👆 💪 📨 📛 🔗 ⚪️➡️ 👆 *➡ 🛠️* 🔢.
@@ -218,7 +218,7 @@ FastAPI (🤙 💃) 🔜 🔁 🔌 🎚-📐 🎚. ⚫️ 🔜 🔌 🎚-🆎
👆 💪 ⚙️ `status_code` 🔢 🌀 ⏮️ `response_class` 🔢:
```Python hl_lines="2 7 9"
{!../../../docs_src/custom_response/tutorial006c.py!}
{!../../docs_src/custom_response/tutorial006c.py!}
```
### `StreamingResponse`
@@ -226,7 +226,7 @@ FastAPI (🤙 💃) 🔜 🔁 🔌 🎚-📐 🎚. ⚫️ 🔜 🔌 🎚-🆎
✊ 🔁 🚂 ⚖️ 😐 🚂/🎻 &amp; 🎏 📨 💪.
```Python hl_lines="2 14"
{!../../../docs_src/custom_response/tutorial007.py!}
{!../../docs_src/custom_response/tutorial007.py!}
```
#### ⚙️ `StreamingResponse` ⏮️ 📁-💖 🎚
@@ -238,7 +238,7 @@ FastAPI (🤙 💃) 🔜 🔁 🔌 🎚-📐 🎚. ⚫️ 🔜 🔌 🎚-🆎
👉 🔌 📚 🗃 🔗 ⏮️ ☁ 💾, 📹 🏭, &amp; 🎏.
```{ .python .annotate hl_lines="2 10-12 14" }
{!../../../docs_src/custom_response/tutorial008.py!}
{!../../docs_src/custom_response/tutorial008.py!}
```
1⃣. 👉 🚂 🔢. ⚫️ "🚂 🔢" ↩️ ⚫️ 🔌 `yield` 📄 🔘.
@@ -269,13 +269,13 @@ FastAPI (🤙 💃) 🔜 🔁 🔌 🎚-📐 🎚. ⚫️ 🔜 🔌 🎚-🆎
📁 📨 🔜 🔌 ☑ `Content-Length`, `Last-Modified` &amp; `ETag` 🎚.
```Python hl_lines="2 10"
{!../../../docs_src/custom_response/tutorial009.py!}
{!../../docs_src/custom_response/tutorial009.py!}
```
👆 💪 ⚙️ `response_class` 🔢:
```Python hl_lines="2 8 10"
{!../../../docs_src/custom_response/tutorial009b.py!}
{!../../docs_src/custom_response/tutorial009b.py!}
```
👉 💼, 👆 💪 📨 📁 ➡ 🔗 ⚪️➡️ 👆 *➡ 🛠️* 🔢.
@@ -291,7 +291,7 @@ FastAPI (🤙 💃) 🔜 🔁 🔌 🎚-📐 🎚. ⚫️ 🔜 🔌 🎚-🆎
👆 💪 ✍ `CustomORJSONResponse`. 👑 👜 👆 ✔️ ✍ `Response.render(content)` 👩‍🔬 👈 📨 🎚 `bytes`:
```Python hl_lines="9-14 17"
{!../../../docs_src/custom_response/tutorial009c.py!}
{!../../docs_src/custom_response/tutorial009c.py!}
```
🔜 ↩️ 🛬:
@@ -319,7 +319,7 @@ FastAPI (🤙 💃) 🔜 🔁 🔌 🎚-📐 🎚. ⚫️ 🔜 🔌 🎚-🆎
🖼 🔛, **FastAPI** 🔜 ⚙️ `ORJSONResponse` 🔢, 🌐 *➡ 🛠️*, ↩️ `JSONResponse`.
```Python hl_lines="2 4"
{!../../../docs_src/custom_response/tutorial010.py!}
{!../../docs_src/custom_response/tutorial010.py!}
```
/// tip

View File

@@ -5,7 +5,7 @@ FastAPI 🏗 🔛 🔝 **Pydantic**, &amp; 👤 ✔️ 🌏 👆 ❔ ⚙️ Pyda
✋️ FastAPI 🐕‍🦺 ⚙️ <a href="https://docs.python.org/3/library/dataclasses.html" class="external-link" target="_blank">`dataclasses`</a> 🎏 🌌:
```Python hl_lines="1 7-12 19-20"
{!../../../docs_src/dataclasses/tutorial001.py!}
{!../../docs_src/dataclasses/tutorial001.py!}
```
👉 🐕‍🦺 👏 **Pydantic**, ⚫️ ✔️ <a href="https://docs.pydantic.dev/latest/concepts/dataclasses/#use-of-stdlib-dataclasses-with-basemodel" class="external-link" target="_blank">🔗 🐕‍🦺 `dataclasses`</a>.
@@ -35,7 +35,7 @@ FastAPI 🏗 🔛 🔝 **Pydantic**, &amp; 👤 ✔️ 🌏 👆 ❔ ⚙️ Pyda
👆 💪 ⚙️ `dataclasses` `response_model` 🔢:
```Python hl_lines="1 7-13 19"
{!../../../docs_src/dataclasses/tutorial002.py!}
{!../../docs_src/dataclasses/tutorial002.py!}
```
🎻 🔜 🔁 🗜 Pydantic 🎻.
@@ -53,7 +53,7 @@ FastAPI 🏗 🔛 🔝 **Pydantic**, &amp; 👤 ✔️ 🌏 👆 ❔ ⚙️ Pyda
👈 💼, 👆 💪 🎯 💱 🐩 `dataclasses` ⏮️ `pydantic.dataclasses`, ❔ 💧-♻:
```{ .python .annotate hl_lines="1 5 8-11 14-17 23-25 28" }
{!../../../docs_src/dataclasses/tutorial003.py!}
{!../../docs_src/dataclasses/tutorial003.py!}
```
1⃣. 👥 🗄 `field` ⚪️➡️ 🐩 `dataclasses`.

View File

@@ -31,7 +31,7 @@
👥 ✍ 🔁 🔢 `lifespan()` ⏮️ `yield` 💖 👉:
```Python hl_lines="16 19"
{!../../../docs_src/events/tutorial003.py!}
{!../../docs_src/events/tutorial003.py!}
```
📥 👥 ⚖ 😥 *🕴* 🛠️ 🚚 🏷 🚮 (❌) 🏷 🔢 📖 ⏮️ 🎰 🏫 🏷 ⏭ `yield`. 👉 📟 🔜 🛠️ **⏭** 🈸 **▶️ ✊ 📨**, ⏮️ *🕴*.
@@ -51,7 +51,7 @@
🥇 👜 👀, 👈 👥 ⚖ 🔁 🔢 ⏮️ `yield`. 👉 📶 🎏 🔗 ⏮️ `yield`.
```Python hl_lines="14-19"
{!../../../docs_src/events/tutorial003.py!}
{!../../docs_src/events/tutorial003.py!}
```
🥇 🍕 🔢, ⏭ `yield`, 🔜 🛠️ **⏭** 🈸 ▶️.
@@ -65,7 +65,7 @@
👈 🗜 🔢 🔘 🕳 🤙 "**🔁 🔑 👨‍💼**".
```Python hl_lines="1 13"
{!../../../docs_src/events/tutorial003.py!}
{!../../docs_src/events/tutorial003.py!}
```
**🔑 👨‍💼** 🐍 🕳 👈 👆 💪 ⚙️ `with` 📄, 🖼, `open()` 💪 ⚙️ 🔑 👨‍💼:
@@ -89,7 +89,7 @@ async with lifespan(app):
`lifespan` 🔢 `FastAPI` 📱 ✊ **🔁 🔑 👨‍💼**, 👥 💪 🚶‍♀️ 👆 🆕 `lifespan` 🔁 🔑 👨‍💼 ⚫️.
```Python hl_lines="22"
{!../../../docs_src/events/tutorial003.py!}
{!../../docs_src/events/tutorial003.py!}
```
## 🎛 🎉 (😢)
@@ -113,7 +113,7 @@ async with lifespan(app):
🚮 🔢 👈 🔜 🏃 ⏭ 🈸 ▶️, 📣 ⚫️ ⏮️ 🎉 `"startup"`:
```Python hl_lines="8"
{!../../../docs_src/events/tutorial001.py!}
{!../../docs_src/events/tutorial001.py!}
```
👉 💼, `startup` 🎉 🐕‍🦺 🔢 🔜 🔢 🏬 "💽" ( `dict`) ⏮️ 💲.
@@ -127,7 +127,7 @@ async with lifespan(app):
🚮 🔢 👈 🔜 🏃 🕐❔ 🈸 🤫 🔽, 📣 ⚫️ ⏮️ 🎉 `"shutdown"`:
```Python hl_lines="6"
{!../../../docs_src/events/tutorial002.py!}
{!../../docs_src/events/tutorial002.py!}
```
📥, `shutdown` 🎉 🐕‍🦺 🔢 🔜 ✍ ✍ ⏸ `"Application shutdown"` 📁 `log.txt`.

View File

@@ -19,7 +19,7 @@
//// tab | 🐍 3⃣.6️⃣ &amp; 🔛
```Python hl_lines="9-11 14-15 18 19 23"
{!> ../../../docs_src/generate_clients/tutorial001.py!}
{!> ../../docs_src/generate_clients/tutorial001.py!}
```
////
@@ -27,7 +27,7 @@
//// tab | 🐍 3⃣.9️⃣ &amp; 🔛
```Python hl_lines="7-9 12-13 16-17 21"
{!> ../../../docs_src/generate_clients/tutorial001_py39.py!}
{!> ../../docs_src/generate_clients/tutorial001_py39.py!}
```
////
@@ -139,7 +139,7 @@ frontend-app@1.0.0 generate-client /home/user/code/frontend-app
//// tab | 🐍 3⃣.6️⃣ &amp; 🔛
```Python hl_lines="23 28 36"
{!> ../../../docs_src/generate_clients/tutorial002.py!}
{!> ../../docs_src/generate_clients/tutorial002.py!}
```
////
@@ -147,7 +147,7 @@ frontend-app@1.0.0 generate-client /home/user/code/frontend-app
//// tab | 🐍 3⃣.9️⃣ &amp; 🔛
```Python hl_lines="21 26 34"
{!> ../../../docs_src/generate_clients/tutorial002_py39.py!}
{!> ../../docs_src/generate_clients/tutorial002_py39.py!}
```
////
@@ -200,7 +200,7 @@ FastAPI ⚙️ **😍 🆔** 🔠 *➡ 🛠️*, ⚫️ ⚙️ **🛠️ 🆔**
//// tab | 🐍 3⃣.6️⃣ &amp; 🔛
```Python hl_lines="8-9 12"
{!> ../../../docs_src/generate_clients/tutorial003.py!}
{!> ../../docs_src/generate_clients/tutorial003.py!}
```
////
@@ -208,7 +208,7 @@ FastAPI ⚙️ **😍 🆔** 🔠 *➡ 🛠️*, ⚫️ ⚙️ **🛠️ 🆔**
//// tab | 🐍 3⃣.9️⃣ &amp; 🔛
```Python hl_lines="6-7 10"
{!> ../../../docs_src/generate_clients/tutorial003_py39.py!}
{!> ../../docs_src/generate_clients/tutorial003_py39.py!}
```
////
@@ -234,7 +234,7 @@ FastAPI ⚙️ **😍 🆔** 🔠 *➡ 🛠️*, ⚫️ ⚙️ **🛠️ 🆔**
👥 💪 ⏬ 🗄 🎻 📁 `openapi.json` &amp; ⤴️ 👥 💪 **❎ 👈 🔡 🔖** ⏮️ ✍ 💖 👉:
```Python
{!../../../docs_src/generate_clients/tutorial004.py!}
{!../../docs_src/generate_clients/tutorial004.py!}
```
⏮️ 👈, 🛠️ 🆔 🔜 📁 ⚪️➡️ 👜 💖 `items-get_items` `get_items`, 👈 🌌 👩‍💻 🚂 💪 🏗 🙅 👩‍🔬 📛.

Some files were not shown because too many files have changed in this diff Show More