mirror of https://github.com/tiangolo/fastapi.git
🔧 Remove `base_path` for `mdx_include` Markdown extension in MkDocs (#12391)
This commit is contained in:
parent
c67b41546c
commit
0f7d67e85c
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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`.
|
||||
|
|
|
|||
|
|
@ -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`.
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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**.
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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.).
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"`.
|
||||
|
|
|
|||
|
|
@ -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,7 +53,7 @@ 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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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>.
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
////
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
🖼, 📣 ➕1️⃣ 📨 ⏮️ 👔 📟 `404` & 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 @@
|
|||
& 📨 ⏮️ 👔 📟 `200` 👈 ⚙️ 👆 `response_model`, ✋️ 🔌 🛃 `example`:
|
||||
|
||||
```Python hl_lines="20-31"
|
||||
{!../../../docs_src/additional_responses/tutorial003.py!}
|
||||
{!../../docs_src/additional_responses/tutorial003.py!}
|
||||
```
|
||||
|
||||
⚫️ 🔜 🌐 🌀 & 🔌 👆 🗄, & 🎦 🛠️ 🩺:
|
||||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
## 🌖 ℹ 🔃 🗄 📨
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
🏆 👈, 🗄 `JSONResponse`, & 📨 👆 🎚 📤 🔗, ⚒ `status_code` 👈 👆 💚:
|
||||
|
||||
```Python hl_lines="4 25"
|
||||
{!../../../docs_src/additional_status_codes/tutorial001.py!}
|
||||
{!../../docs_src/additional_status_codes/tutorial001.py!}
|
||||
```
|
||||
|
||||
/// warning
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
👈, 👥 📣 👩🔬 `__call__`:
|
||||
|
||||
```Python hl_lines="10"
|
||||
{!../../../docs_src/dependencies/tutorial011.py!}
|
||||
{!../../docs_src/dependencies/tutorial011.py!}
|
||||
```
|
||||
|
||||
👉 💼, 👉 `__call__` ⚫️❔ **FastAPI** 🔜 ⚙️ ✅ 🌖 🔢 & 🎧-🔗, & 👉 ⚫️❔ 🔜 🤙 🚶♀️ 💲 🔢 👆 *➡ 🛠️ 🔢* ⏪.
|
||||
|
|
@ -29,7 +29,7 @@
|
|||
& 🔜, 👥 💪 ⚙️ `__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!}
|
||||
```
|
||||
|
||||
& 👈 🌌 👥 💪 "🔗" 👆 🔗, 👈 🔜 ✔️ `"bar"` 🔘 ⚫️, 🔢 `checker.fixed_content`.
|
||||
|
|
@ -57,7 +57,7 @@ checker(q="somequery")
|
|||
...& 🚶♀️ ⚫️❔ 👈 📨 💲 🔗 👆 *➡ 🛠️ 🔢* 🔢 `fixed_content_included`:
|
||||
|
||||
```Python hl_lines="20"
|
||||
{!../../../docs_src/dependencies/tutorial011.py!}
|
||||
{!../../docs_src/dependencies/tutorial011.py!}
|
||||
```
|
||||
|
||||
/// tip
|
||||
|
|
|
|||
|
|
@ -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` ⏮️ 📱, & 📨 🔁 📨 ⚫️, ⚙️ `await`.
|
||||
|
||||
```Python hl_lines="9-12"
|
||||
{!../../../docs_src/async_tests/test_main.py!}
|
||||
{!../../docs_src/async_tests/test_main.py!}
|
||||
```
|
||||
|
||||
👉 🌓:
|
||||
|
|
|
|||
|
|
@ -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!}
|
||||
```
|
||||
|
||||
& ⤴️ ⚫️ 🏆 🚫 🔌 ⚫️ 🗄 🔗.
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
✋️ 🚥 👆 🎯 👈 🎚 👈 👆 🛬 **🎻 ⏮️ 🎻**, 👆 💪 🚶♀️ ⚫️ 🔗 📨 🎓 & ❎ ➕ 🌥 👈 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()` ⏪ 🏗 & 📨 `Response` ↩️ 🛬 🕸 `str`.
|
||||
|
|
@ -145,7 +145,7 @@
|
|||
FastAPI (🤙 💃) 🔜 🔁 🔌 🎚-📐 🎚. ⚫️ 🔜 🔌 🎚-🆎 🎚, ⚓️ 🔛 = & 🔁 = ✍ 🆎.
|
||||
|
||||
```Python hl_lines="1 18"
|
||||
{!../../../docs_src/response_directly/tutorial002.py!}
|
||||
{!../../docs_src/response_directly/tutorial002.py!}
|
||||
```
|
||||
|
||||
### `HTMLResponse`
|
||||
|
|
@ -157,7 +157,7 @@ FastAPI (🤙 💃) 🔜 🔁 🔌 🎚-📐 🎚. ⚫️ 🔜 🔌 🎚-🆎
|
|||
✊ ✍ ⚖️ 🔢 & 📨 ✅ ✍ 📨.
|
||||
|
||||
```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 (🤙 💃) 🔜 🔁 🔌 🎚-📐 🎚. ⚫️ 🔜 🔌 🎚-🆎
|
|||
✊ 🔁 🚂 ⚖️ 😐 🚂/🎻 & 🎏 📨 💪.
|
||||
|
||||
```Python hl_lines="2 14"
|
||||
{!../../../docs_src/custom_response/tutorial007.py!}
|
||||
{!../../docs_src/custom_response/tutorial007.py!}
|
||||
```
|
||||
|
||||
#### ⚙️ `StreamingResponse` ⏮️ 📁-💖 🎚
|
||||
|
|
@ -238,7 +238,7 @@ FastAPI (🤙 💃) 🔜 🔁 🔌 🎚-📐 🎚. ⚫️ 🔜 🔌 🎚-🆎
|
|||
👉 🔌 📚 🗃 🔗 ⏮️ ☁ 💾, 📹 🏭, & 🎏.
|
||||
|
||||
```{ .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` & `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
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ FastAPI 🏗 🔛 🔝 **Pydantic**, & 👤 ✔️ 🌏 👆 ❔ ⚙️ 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**, & 👤 ✔️ 🌏 👆 ❔ ⚙️ 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**, & 👤 ✔️ 🌏 👆 ❔ ⚙️ 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`.
|
||||
|
|
|
|||
|
|
@ -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`.
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
//// tab | 🐍 3️⃣.6️⃣ & 🔛
|
||||
|
||||
```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️⃣ & 🔛
|
||||
|
||||
```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️⃣ & 🔛
|
||||
|
||||
```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️⃣ & 🔛
|
||||
|
||||
```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️⃣ & 🔛
|
||||
|
||||
```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️⃣ & 🔛
|
||||
|
||||
```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` & ⤴️ 👥 💪 **❎ 👈 🔡 🔖** ⏮️ ✍ 💖 👉:
|
||||
|
||||
```Python
|
||||
{!../../../docs_src/generate_clients/tutorial004.py!}
|
||||
{!../../docs_src/generate_clients/tutorial004.py!}
|
||||
```
|
||||
|
||||
⏮️ 👈, 🛠️ 🆔 🔜 📁 ⚪️➡️ 👜 💖 `items-get_items` `get_items`, 👈 🌌 👩💻 🚂 💪 🏗 🙅 👩🔬 📛.
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ app.add_middleware(UnicornMiddleware, some_config="rainbow")
|
|||
🙆 📨 📨 `http` ⚖️ `ws` 🔜 ❎ 🔐 ⚖ ↩️.
|
||||
|
||||
```Python hl_lines="2 6"
|
||||
{!../../../docs_src/advanced_middleware/tutorial001.py!}
|
||||
{!../../docs_src/advanced_middleware/tutorial001.py!}
|
||||
```
|
||||
|
||||
## `TrustedHostMiddleware`
|
||||
|
|
@ -66,7 +66,7 @@ app.add_middleware(UnicornMiddleware, some_config="rainbow")
|
|||
🛠️ 👈 🌐 📨 📨 ✔️ ☑ ⚒ `Host` 🎚, ✔ 💂♂ 🛡 🇺🇸🔍 🦠 🎚 👊.
|
||||
|
||||
```Python hl_lines="2 6-8"
|
||||
{!../../../docs_src/advanced_middleware/tutorial002.py!}
|
||||
{!../../docs_src/advanced_middleware/tutorial002.py!}
|
||||
```
|
||||
|
||||
📄 ❌ 🐕🦺:
|
||||
|
|
@ -82,7 +82,7 @@ app.add_middleware(UnicornMiddleware, some_config="rainbow")
|
|||
🛠️ 🔜 🍵 👯♂️ 🐩 & 🎥 📨.
|
||||
|
||||
```Python hl_lines="2 6"
|
||||
{!../../../docs_src/advanced_middleware/tutorial003.py!}
|
||||
{!../../docs_src/advanced_middleware/tutorial003.py!}
|
||||
```
|
||||
|
||||
📄 ❌ 🐕🦺:
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
👉 🍕 📶 😐, 🌅 📟 🎲 ⏪ 😰 👆:
|
||||
|
||||
```Python hl_lines="9-13 36-53"
|
||||
{!../../../docs_src/openapi_callbacks/tutorial001.py!}
|
||||
{!../../docs_src/openapi_callbacks/tutorial001.py!}
|
||||
```
|
||||
|
||||
/// tip
|
||||
|
|
@ -93,7 +93,7 @@ httpx.post(callback_url, json={"description": "Invoice paid", "paid": True})
|
|||
🥇 ✍ 🆕 `APIRouter` 👈 🔜 🔌 1️⃣ ⚖️ 🌅 ⏲.
|
||||
|
||||
```Python hl_lines="3 25"
|
||||
{!../../../docs_src/openapi_callbacks/tutorial001.py!}
|
||||
{!../../docs_src/openapi_callbacks/tutorial001.py!}
|
||||
```
|
||||
|
||||
### ✍ ⏲ *➡ 🛠️*
|
||||
|
|
@ -106,7 +106,7 @@ httpx.post(callback_url, json={"description": "Invoice paid", "paid": True})
|
|||
* & ⚫️ 💪 ✔️ 📄 📨 ⚫️ 🔜 📨, ✅ `response_model=InvoiceEventReceived`.
|
||||
|
||||
```Python hl_lines="16-18 21-22 28-32"
|
||||
{!../../../docs_src/openapi_callbacks/tutorial001.py!}
|
||||
{!../../docs_src/openapi_callbacks/tutorial001.py!}
|
||||
```
|
||||
|
||||
📤 2️⃣ 👑 🔺 ⚪️➡️ 😐 *➡ 🛠️*:
|
||||
|
|
@ -176,7 +176,7 @@ https://www.external.org/events/invoices/2expen51ve
|
|||
🔜 ⚙️ 🔢 `callbacks` *👆 🛠️ ➡ 🛠️ 👨🎨* 🚶♀️ 🔢 `.routes` (👈 🤙 `list` 🛣/*➡ 🛠️*) ⚪️➡️ 👈 ⏲ 📻:
|
||||
|
||||
```Python hl_lines="35"
|
||||
{!../../../docs_src/openapi_callbacks/tutorial001.py!}
|
||||
{!../../docs_src/openapi_callbacks/tutorial001.py!}
|
||||
```
|
||||
|
||||
/// tip
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
👆 🔜 ✔️ ⚒ 💭 👈 ⚫️ 😍 🔠 🛠️.
|
||||
|
||||
```Python hl_lines="6"
|
||||
{!../../../docs_src/path_operation_advanced_configuration/tutorial001.py!}
|
||||
{!../../docs_src/path_operation_advanced_configuration/tutorial001.py!}
|
||||
```
|
||||
|
||||
### ⚙️ *➡ 🛠️ 🔢* 📛 {
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
👆 🔜 ⚫️ ⏮️ ❎ 🌐 👆 *➡ 🛠️*.
|
||||
|
||||
```Python hl_lines="2 12-21 24"
|
||||
{!../../../docs_src/path_operation_advanced_configuration/tutorial002.py!}
|
||||
{!../../docs_src/path_operation_advanced_configuration/tutorial002.py!}
|
||||
```
|
||||
|
||||
/// tip
|
||||
|
|
@ -45,7 +45,7 @@
|
|||
🚫 *➡ 🛠️* ⚪️➡️ 🏗 🗄 🔗 (& ➡️, ⚪️➡️ 🏧 🧾 ⚙️), ⚙️ 🔢 `include_in_schema` & ⚒ ⚫️ `False`:
|
||||
|
||||
```Python hl_lines="6"
|
||||
{!../../../docs_src/path_operation_advanced_configuration/tutorial003.py!}
|
||||
{!../../docs_src/path_operation_advanced_configuration/tutorial003.py!}
|
||||
```
|
||||
|
||||
## 🏧 📛 ⚪️➡️ #️⃣
|
||||
|
|
@ -57,7 +57,7 @@
|
|||
⚫️ 🏆 🚫 🎦 🆙 🧾, ✋️ 🎏 🧰 (✅ 🐉) 🔜 💪 ⚙️ 🎂.
|
||||
|
||||
```Python hl_lines="19-29"
|
||||
{!../../../docs_src/path_operation_advanced_configuration/tutorial004.py!}
|
||||
{!../../docs_src/path_operation_advanced_configuration/tutorial004.py!}
|
||||
```
|
||||
|
||||
## 🌖 📨
|
||||
|
|
@ -101,7 +101,7 @@
|
|||
👉 `openapi_extra` 💪 👍, 🖼, 📣 [🗄 ↔](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specificationExtensions):
|
||||
|
||||
```Python hl_lines="6"
|
||||
{!../../../docs_src/path_operation_advanced_configuration/tutorial005.py!}
|
||||
{!../../docs_src/path_operation_advanced_configuration/tutorial005.py!}
|
||||
```
|
||||
|
||||
🚥 👆 📂 🏧 🛠️ 🩺, 👆 ↔ 🔜 🎦 🆙 🔝 🎯 *➡ 🛠️*.
|
||||
|
|
@ -150,7 +150,7 @@
|
|||
👆 💪 👈 ⏮️ `openapi_extra`:
|
||||
|
||||
```Python hl_lines="20-37 39-40"
|
||||
{!../../../docs_src/path_operation_advanced_configuration/tutorial006.py!}
|
||||
{!../../docs_src/path_operation_advanced_configuration/tutorial006.py!}
|
||||
```
|
||||
|
||||
👉 🖼, 👥 🚫 📣 🙆 Pydantic 🏷. 👐, 📨 💪 🚫 <abbr title="converted from some plain format, like bytes, into Python objects">🎻</abbr> 🎻, ⚫️ ✍ 🔗 `bytes`, & 🔢 `magic_data_reader()` 🔜 🈚 🎻 ⚫️ 🌌.
|
||||
|
|
@ -166,7 +166,7 @@
|
|||
🖼, 👉 🈸 👥 🚫 ⚙️ FastAPI 🛠️ 🛠️ ⚗ 🎻 🔗 ⚪️➡️ Pydantic 🏷 🚫 🏧 🔬 🎻. 👐, 👥 📣 📨 🎚 🆎 📁, 🚫 🎻:
|
||||
|
||||
```Python hl_lines="17-22 24"
|
||||
{!../../../docs_src/path_operation_advanced_configuration/tutorial007.py!}
|
||||
{!../../docs_src/path_operation_advanced_configuration/tutorial007.py!}
|
||||
```
|
||||
|
||||
👐, 👐 👥 🚫 ⚙️ 🔢 🛠️ 🛠️, 👥 ⚙️ Pydantic 🏷 ❎ 🏗 🎻 🔗 💽 👈 👥 💚 📨 📁.
|
||||
|
|
@ -176,7 +176,7 @@
|
|||
& ⤴️ 👆 📟, 👥 🎻 👈 📁 🎚 🔗, & ⤴️ 👥 🔄 ⚙️ 🎏 Pydantic 🏷 ✔ 📁 🎚:
|
||||
|
||||
```Python hl_lines="26-33"
|
||||
{!../../../docs_src/path_operation_advanced_configuration/tutorial007.py!}
|
||||
{!../../docs_src/path_operation_advanced_configuration/tutorial007.py!}
|
||||
```
|
||||
|
||||
/// tip
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
& ⤴️ 👆 💪 ⚒ `status_code` 👈 *🔀* 📨 🎚.
|
||||
|
||||
```Python hl_lines="1 9 12"
|
||||
{!../../../docs_src/response_change_status_code/tutorial001.py!}
|
||||
{!../../docs_src/response_change_status_code/tutorial001.py!}
|
||||
```
|
||||
|
||||
& ⤴️ 👆 💪 📨 🙆 🎚 👆 💪, 👆 🛎 🔜 ( `dict`, 💽 🏷, ♒️).
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
& ⤴️ 👆 💪 ⚒ 🍪 👈 *🔀* 📨 🎚.
|
||||
|
||||
```Python hl_lines="1 8-9"
|
||||
{!../../../docs_src/response_cookies/tutorial002.py!}
|
||||
{!../../docs_src/response_cookies/tutorial002.py!}
|
||||
```
|
||||
|
||||
& ⤴️ 👆 💪 📨 🙆 🎚 👆 💪, 👆 🛎 🔜 ( `dict`, 💽 🏷, ♒️).
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
⤴️ ⚒ 🍪 ⚫️, & ⤴️ 📨 ⚫️:
|
||||
|
||||
```Python hl_lines="10-12"
|
||||
{!../../../docs_src/response_cookies/tutorial001.py!}
|
||||
{!../../docs_src/response_cookies/tutorial001.py!}
|
||||
```
|
||||
|
||||
/// tip
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
📚 💼, 👆 💪 ⚙️ `jsonable_encoder` 🗜 👆 📊 ⏭ 🚶♀️ ⚫️ 📨:
|
||||
|
||||
```Python hl_lines="6-7 21-22"
|
||||
{!../../../docs_src/response_directly/tutorial001.py!}
|
||||
{!../../docs_src/response_directly/tutorial001.py!}
|
||||
```
|
||||
|
||||
/// note | "📡 ℹ"
|
||||
|
|
@ -57,7 +57,7 @@
|
|||
👆 💪 🚮 👆 📂 🎚 🎻, 🚮 ⚫️ `Response`, & 📨 ⚫️:
|
||||
|
||||
```Python hl_lines="1 18"
|
||||
{!../../../docs_src/response_directly/tutorial002.py!}
|
||||
{!../../docs_src/response_directly/tutorial002.py!}
|
||||
```
|
||||
|
||||
## 🗒
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
& ⤴️ 👆 💪 ⚒ 🎚 👈 *🔀* 📨 🎚.
|
||||
|
||||
```Python hl_lines="1 7-8"
|
||||
{!../../../docs_src/response_headers/tutorial002.py!}
|
||||
{!../../docs_src/response_headers/tutorial002.py!}
|
||||
```
|
||||
|
||||
& ⤴️ 👆 💪 📨 🙆 🎚 👆 💪, 👆 🛎 🔜 ( `dict`, 💽 🏷, ♒️).
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
✍ 📨 🔬 [📨 📨 🔗](response-directly.md){.internal-link target=_blank} & 🚶♀️ 🎚 🌖 🔢:
|
||||
|
||||
```Python hl_lines="10-12"
|
||||
{!../../../docs_src/response_headers/tutorial001.py!}
|
||||
{!../../docs_src/response_headers/tutorial001.py!}
|
||||
```
|
||||
|
||||
/// note | "📡 ℹ"
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
* ⚫️ 🔌 `username` & `password` 📨.
|
||||
|
||||
```Python hl_lines="2 6 10"
|
||||
{!../../../docs_src/security/tutorial006.py!}
|
||||
{!../../docs_src/security/tutorial006.py!}
|
||||
```
|
||||
|
||||
🕐❔ 👆 🔄 📂 📛 🥇 🕰 (⚖️ 🖊 "🛠️" 🔼 🩺) 🖥 🔜 💭 👆 👆 🆔 & 🔐:
|
||||
|
|
@ -43,7 +43,7 @@
|
|||
⤴️ 👥 💪 ⚙️ `secrets.compare_digest()` 🚚 👈 `credentials.username` `"stanleyjobson"`, & 👈 `credentials.password` `"swordfish"`.
|
||||
|
||||
```Python hl_lines="1 11-21"
|
||||
{!../../../docs_src/security/tutorial007.py!}
|
||||
{!../../docs_src/security/tutorial007.py!}
|
||||
```
|
||||
|
||||
👉 🔜 🎏:
|
||||
|
|
@ -109,5 +109,5 @@ if "stanleyjobsox" == "stanleyjobson" and "love123" == "swordfish":
|
|||
⏮️ 🔍 👈 🎓 ❌, 📨 `HTTPException` ⏮️ 👔 📟 4️⃣0️⃣1️⃣ (🎏 📨 🕐❔ 🙅♂ 🎓 🚚) & 🚮 🎚 `WWW-Authenticate` ⚒ 🖥 🎦 💳 📋 🔄:
|
||||
|
||||
```Python hl_lines="23-27"
|
||||
{!../../../docs_src/security/tutorial007.py!}
|
||||
{!../../docs_src/security/tutorial007.py!}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ Oauth2️⃣ 👫 🎻.
|
|||
🥇, ➡️ 🔜 👀 🍕 👈 🔀 ⚪️➡️ 🖼 👑 **🔰 - 👩💻 🦮** [Oauth2️⃣ ⏮️ 🔐 (& 🔁), 📨 ⏮️ 🥙 🤝](../../tutorial/security/oauth2-jwt.md){.internal-link target=_blank}. 🔜 ⚙️ Oauth2️⃣ ↔:
|
||||
|
||||
```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!}
|
||||
```
|
||||
|
||||
🔜 ➡️ 📄 👈 🔀 🔁 🔁.
|
||||
|
|
@ -75,7 +75,7 @@ Oauth2️⃣ 👫 🎻.
|
|||
`scopes` 🔢 📨 `dict` ⏮️ 🔠 ↔ 🔑 & 📛 💲:
|
||||
|
||||
```Python hl_lines="62-65"
|
||||
{!../../../docs_src/security/tutorial005.py!}
|
||||
{!../../docs_src/security/tutorial005.py!}
|
||||
```
|
||||
|
||||
↩️ 👥 🔜 📣 📚 ↔, 👫 🔜 🎦 🆙 🛠️ 🩺 🕐❔ 👆 🕹-/✔.
|
||||
|
|
@ -103,7 +103,7 @@ Oauth2️⃣ 👫 🎻.
|
|||
///
|
||||
|
||||
```Python hl_lines="155"
|
||||
{!../../../docs_src/security/tutorial005.py!}
|
||||
{!../../docs_src/security/tutorial005.py!}
|
||||
```
|
||||
|
||||
## 📣 ↔ *➡ 🛠️* & 🔗
|
||||
|
|
@ -131,7 +131,7 @@ Oauth2️⃣ 👫 🎻.
|
|||
///
|
||||
|
||||
```Python hl_lines="4 139 168"
|
||||
{!../../../docs_src/security/tutorial005.py!}
|
||||
{!../../docs_src/security/tutorial005.py!}
|
||||
```
|
||||
|
||||
/// info | "📡 ℹ"
|
||||
|
|
@ -159,7 +159,7 @@ Oauth2️⃣ 👫 🎻.
|
|||
👉 `SecurityScopes` 🎓 🎏 `Request` (`Request` ⚙️ 🤚 📨 🎚 🔗).
|
||||
|
||||
```Python hl_lines="8 105"
|
||||
{!../../../docs_src/security/tutorial005.py!}
|
||||
{!../../docs_src/security/tutorial005.py!}
|
||||
```
|
||||
|
||||
## ⚙️ `scopes`
|
||||
|
|
@ -175,7 +175,7 @@ Oauth2️⃣ 👫 🎻.
|
|||
👉 ⚠, 👥 🔌 ↔ 🚚 (🚥 🙆) 🎻 👽 🚀 (⚙️ `scope_str`). 👥 🚮 👈 🎻 ⚗ ↔ `WWW-Authenticate` 🎚 (👉 🍕 🔌).
|
||||
|
||||
```Python hl_lines="105 107-115"
|
||||
{!../../../docs_src/security/tutorial005.py!}
|
||||
{!../../docs_src/security/tutorial005.py!}
|
||||
```
|
||||
|
||||
## ✔ `username` & 💽 💠
|
||||
|
|
@ -193,7 +193,7 @@ Oauth2️⃣ 👫 🎻.
|
|||
👥 ✔ 👈 👥 ✔️ 👩💻 ⏮️ 👈 🆔, & 🚥 🚫, 👥 🤚 👈 🎏 ⚠ 👥 ✍ ⏭.
|
||||
|
||||
```Python hl_lines="46 116-127"
|
||||
{!../../../docs_src/security/tutorial005.py!}
|
||||
{!../../docs_src/security/tutorial005.py!}
|
||||
```
|
||||
|
||||
## ✔ `scopes`
|
||||
|
|
@ -203,7 +203,7 @@ Oauth2️⃣ 👫 🎻.
|
|||
👉, 👥 ⚙️ `security_scopes.scopes`, 👈 🔌 `list` ⏮️ 🌐 👫 ↔ `str`.
|
||||
|
||||
```Python hl_lines="128-134"
|
||||
{!../../../docs_src/security/tutorial005.py!}
|
||||
{!../../docs_src/security/tutorial005.py!}
|
||||
```
|
||||
|
||||
## 🔗 🌲 & ↔
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ Hello World from Python
|
|||
👆 💪 ⚙️ 🌐 🎏 🔬 ⚒ & 🧰 👆 ⚙️ Pydantic 🏷, 💖 🎏 📊 🆎 & 🌖 🔬 ⏮️ `Field()`.
|
||||
|
||||
```Python hl_lines="2 5-8 11"
|
||||
{!../../../docs_src/settings/tutorial001.py!}
|
||||
{!../../docs_src/settings/tutorial001.py!}
|
||||
```
|
||||
|
||||
/// tip
|
||||
|
|
@ -167,7 +167,7 @@ Hello World from Python
|
|||
⤴️ 👆 💪 ⚙️ 🆕 `settings` 🎚 👆 🈸:
|
||||
|
||||
```Python hl_lines="18-20"
|
||||
{!../../../docs_src/settings/tutorial001.py!}
|
||||
{!../../docs_src/settings/tutorial001.py!}
|
||||
```
|
||||
|
||||
### 🏃 💽
|
||||
|
|
@ -203,13 +203,13 @@ $ ADMIN_EMAIL="deadpool@example.com" APP_NAME="ChimichangApp" uvicorn main:app
|
|||
🖼, 👆 💪 ✔️ 📁 `config.py` ⏮️:
|
||||
|
||||
```Python
|
||||
{!../../../docs_src/settings/app01/config.py!}
|
||||
{!../../docs_src/settings/app01/config.py!}
|
||||
```
|
||||
|
||||
& ⤴️ ⚙️ ⚫️ 📁 `main.py`:
|
||||
|
||||
```Python hl_lines="3 11-13"
|
||||
{!../../../docs_src/settings/app01/main.py!}
|
||||
{!../../docs_src/settings/app01/main.py!}
|
||||
```
|
||||
|
||||
/// tip
|
||||
|
|
@ -229,7 +229,7 @@ $ ADMIN_EMAIL="deadpool@example.com" APP_NAME="ChimichangApp" uvicorn main:app
|
|||
👟 ⚪️➡️ ⏮️ 🖼, 👆 `config.py` 📁 💪 👀 💖:
|
||||
|
||||
```Python hl_lines="10"
|
||||
{!../../../docs_src/settings/app02/config.py!}
|
||||
{!../../docs_src/settings/app02/config.py!}
|
||||
```
|
||||
|
||||
👀 👈 🔜 👥 🚫 ✍ 🔢 👐 `settings = Settings()`.
|
||||
|
|
@ -239,7 +239,7 @@ $ ADMIN_EMAIL="deadpool@example.com" APP_NAME="ChimichangApp" uvicorn main:app
|
|||
🔜 👥 ✍ 🔗 👈 📨 🆕 `config.Settings()`.
|
||||
|
||||
```Python hl_lines="5 11-12"
|
||||
{!../../../docs_src/settings/app02/main.py!}
|
||||
{!../../docs_src/settings/app02/main.py!}
|
||||
```
|
||||
|
||||
/// tip
|
||||
|
|
@ -253,7 +253,7 @@ $ ADMIN_EMAIL="deadpool@example.com" APP_NAME="ChimichangApp" uvicorn main:app
|
|||
& ⤴️ 👥 💪 🚚 ⚫️ ⚪️➡️ *➡ 🛠️ 🔢* 🔗 & ⚙️ ⚫️ 🙆 👥 💪 ⚫️.
|
||||
|
||||
```Python hl_lines="16 18-20"
|
||||
{!../../../docs_src/settings/app02/main.py!}
|
||||
{!../../docs_src/settings/app02/main.py!}
|
||||
```
|
||||
|
||||
### ⚒ & 🔬
|
||||
|
|
@ -261,7 +261,7 @@ $ ADMIN_EMAIL="deadpool@example.com" APP_NAME="ChimichangApp" uvicorn main:app
|
|||
⤴️ ⚫️ 🔜 📶 ⏩ 🚚 🎏 ⚒ 🎚 ⏮️ 🔬 🏗 🔗 🔐 `get_settings`:
|
||||
|
||||
```Python hl_lines="9-10 13 21"
|
||||
{!../../../docs_src/settings/app02/test_main.py!}
|
||||
{!../../docs_src/settings/app02/test_main.py!}
|
||||
```
|
||||
|
||||
🔗 🔐 👥 ⚒ 🆕 💲 `admin_email` 🕐❔ 🏗 🆕 `Settings` 🎚, & ⤴️ 👥 📨 👈 🆕 🎚.
|
||||
|
|
@ -304,7 +304,7 @@ APP_NAME="ChimichangApp"
|
|||
& ⤴️ ℹ 👆 `config.py` ⏮️:
|
||||
|
||||
```Python hl_lines="9-10"
|
||||
{!../../../docs_src/settings/app03/config.py!}
|
||||
{!../../docs_src/settings/app03/config.py!}
|
||||
```
|
||||
|
||||
📥 👥 ✍ 🎓 `Config` 🔘 👆 Pydantic `Settings` 🎓, & ⚒ `env_file` 📁 ⏮️ 🇨🇻 📁 👥 💚 ⚙️.
|
||||
|
|
@ -339,7 +339,7 @@ def get_settings():
|
|||
✋️ 👥 ⚙️ `@lru_cache` 👨🎨 🔛 🔝, `Settings` 🎚 🔜 ✍ 🕴 🕐, 🥇 🕰 ⚫️ 🤙. 👶 👶
|
||||
|
||||
```Python hl_lines="1 10"
|
||||
{!../../../docs_src/settings/app03/main.py!}
|
||||
{!../../docs_src/settings/app03/main.py!}
|
||||
```
|
||||
|
||||
⤴️ 🙆 🏁 🤙 `get_settings()` 🔗 ⏭ 📨, ↩️ 🛠️ 🔗 📟 `get_settings()` & 🏗 🆕 `Settings` 🎚, ⚫️ 🔜 📨 🎏 🎚 👈 📨 🔛 🥇 🤙, 🔄 & 🔄.
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
🥇, ✍ 👑, 🔝-🎚, **FastAPI** 🈸, & 🚮 *➡ 🛠️*:
|
||||
|
||||
```Python hl_lines="3 6-8"
|
||||
{!../../../docs_src/sub_applications/tutorial001.py!}
|
||||
{!../../docs_src/sub_applications/tutorial001.py!}
|
||||
```
|
||||
|
||||
### 🎧-🈸
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
👉 🎧-🈸 ➕1️⃣ 🐩 FastAPI 🈸, ✋️ 👉 1️⃣ 👈 🔜 "🗻":
|
||||
|
||||
```Python hl_lines="11 14-16"
|
||||
{!../../../docs_src/sub_applications/tutorial001.py!}
|
||||
{!../../docs_src/sub_applications/tutorial001.py!}
|
||||
```
|
||||
|
||||
### 🗻 🎧-🈸
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
👉 💼, ⚫️ 🔜 📌 ➡ `/subapi`:
|
||||
|
||||
```Python hl_lines="11 19"
|
||||
{!../../../docs_src/sub_applications/tutorial001.py!}
|
||||
{!../../docs_src/sub_applications/tutorial001.py!}
|
||||
```
|
||||
|
||||
### ✅ 🏧 🛠️ 🩺
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ $ pip install jinja2
|
|||
* ⚙️ `templates` 👆 ✍ ✍ & 📨 `TemplateResponse`, 🚶♀️ `request` 1️⃣ 🔑-💲 👫 Jinja2️⃣ "🔑".
|
||||
|
||||
```Python hl_lines="4 11 15-18"
|
||||
{!../../../docs_src/templates/tutorial001.py!}
|
||||
{!../../docs_src/templates/tutorial001.py!}
|
||||
```
|
||||
|
||||
/// note
|
||||
|
|
@ -56,7 +56,7 @@ $ pip install jinja2
|
|||
⤴️ 👆 💪 ✍ 📄 `templates/item.html` ⏮️:
|
||||
|
||||
```jinja hl_lines="7"
|
||||
{!../../../docs_src/templates/templates/item.html!}
|
||||
{!../../docs_src/templates/templates/item.html!}
|
||||
```
|
||||
|
||||
⚫️ 🔜 🎦 `id` ✊ ⚪️➡️ "🔑" `dict` 👆 🚶♀️:
|
||||
|
|
@ -70,13 +70,13 @@ $ pip install jinja2
|
|||
& 👆 💪 ⚙️ `url_for()` 🔘 📄, & ⚙️ ⚫️, 🖼, ⏮️ `StaticFiles` 👆 📌.
|
||||
|
||||
```jinja hl_lines="4"
|
||||
{!../../../docs_src/templates/templates/item.html!}
|
||||
{!../../docs_src/templates/templates/item.html!}
|
||||
```
|
||||
|
||||
👉 🖼, ⚫️ 🔜 🔗 🎚 📁 `static/styles.css` ⏮️:
|
||||
|
||||
```CSS hl_lines="4"
|
||||
{!../../../docs_src/templates/static/styles.css!}
|
||||
{!../../docs_src/templates/static/styles.css!}
|
||||
```
|
||||
|
||||
& ↩️ 👆 ⚙️ `StaticFiles`, 👈 🎚 📁 🔜 🍦 🔁 👆 **FastAPI** 🈸 📛 `/static/styles.css`.
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@
|
|||
✋️ 🎂 🎉 📟 🌅 ⚖️ 🌘 🎏, 👥 📁 ⚫️.
|
||||
|
||||
```Python hl_lines="8-13"
|
||||
{!../../../docs_src/sql_databases/sql_app/tests/test_sql_app.py!}
|
||||
{!../../docs_src/sql_databases/sql_app/tests/test_sql_app.py!}
|
||||
```
|
||||
|
||||
/// tip
|
||||
|
|
@ -73,7 +73,7 @@ Base.metadata.create_all(bind=engine)
|
|||
👥 🚮 👈 ⏸ 📥, ⏮️ 🆕 📁.
|
||||
|
||||
```Python hl_lines="16"
|
||||
{!../../../docs_src/sql_databases/sql_app/tests/test_sql_app.py!}
|
||||
{!../../docs_src/sql_databases/sql_app/tests/test_sql_app.py!}
|
||||
```
|
||||
|
||||
## 🔗 🔐
|
||||
|
|
@ -81,7 +81,7 @@ Base.metadata.create_all(bind=engine)
|
|||
🔜 👥 ✍ 🔗 🔐 & 🚮 ⚫️ 🔐 👆 📱.
|
||||
|
||||
```Python hl_lines="19-24 27"
|
||||
{!../../../docs_src/sql_databases/sql_app/tests/test_sql_app.py!}
|
||||
{!../../docs_src/sql_databases/sql_app/tests/test_sql_app.py!}
|
||||
```
|
||||
|
||||
/// tip
|
||||
|
|
@ -95,7 +95,7 @@ Base.metadata.create_all(bind=engine)
|
|||
⤴️ 👥 💪 💯 📱 🛎.
|
||||
|
||||
```Python hl_lines="32-47"
|
||||
{!../../../docs_src/sql_databases/sql_app/tests/test_sql_app.py!}
|
||||
{!../../docs_src/sql_databases/sql_app/tests/test_sql_app.py!}
|
||||
```
|
||||
|
||||
& 🌐 🛠️ 👥 ⚒ 💽 ⏮️ 💯 🔜 `test.db` 💽 ↩️ 👑 `sql_app.db`.
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
& ⤴️ **FastAPI** 🔜 🤙 👈 🔐 ↩️ ⏮️ 🔗.
|
||||
|
||||
```Python hl_lines="28-29 32"
|
||||
{!../../../docs_src/dependency_testing/tutorial001.py!}
|
||||
{!../../docs_src/dependency_testing/tutorial001.py!}
|
||||
```
|
||||
|
||||
/// tip
|
||||
|
|
|
|||
|
|
@ -3,5 +3,5 @@
|
|||
🕐❔ 👆 💪 👆 🎉 🐕🦺 (`startup` & `shutdown`) 🏃 👆 💯, 👆 💪 ⚙️ `TestClient` ⏮️ `with` 📄:
|
||||
|
||||
```Python hl_lines="9-12 20-24"
|
||||
{!../../../docs_src/app_testing/tutorial003.py!}
|
||||
{!../../docs_src/app_testing/tutorial003.py!}
|
||||
```
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue