9.2 KiB
💪 - 🔁 🏷
⏮️ FastAPI, 👆 💪 🔬, ✔, 📄, & ⚙️ 🎲 🙇 🐦 🏷 (👏 Pydantic).
📇 🏑
👆 💪 🔬 🔢 🏾. 🖼, 🐍 list
:
=== "🐍 3️⃣.6️⃣ & 🔛"
```Python hl_lines="14"
{!> ../../../docs_src/body_nested_models/tutorial001.py!}
```
=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"
```Python hl_lines="12"
{!> ../../../docs_src/body_nested_models/tutorial001_py310.py!}
```
👉 🔜 ⚒ tags
📇, 👐 ⚫️ 🚫 📣 🆎 🔣 📇.
📇 🏑 ⏮️ 🆎 🔢
✋️ 🐍 ✔️ 🎯 🌌 📣 📇 ⏮️ 🔗 🆎, ⚖️ "🆎 🔢":
🗄 ⌨ List
🐍 3️⃣.9️⃣ & 🔛 👆 💪 ⚙️ 🐩 list
📣 👫 🆎 ✍ 👥 🔜 👀 🔛. 👶
✋️ 🐍 ⏬ ⏭ 3️⃣.9️⃣ (3️⃣.6️⃣ & 🔛), 👆 🥇 💪 🗄 List
⚪️➡️ 🐩 🐍 typing
🕹:
{!> ../../../docs_src/body_nested_models/tutorial002.py!}
📣 list
⏮️ 🆎 🔢
📣 🆎 👈 ✔️ 🆎 🔢 (🔗 🆎), 💖 list
, dict
, tuple
:
- 🚥 👆 🐍 ⏬ 🔅 🌘 3️⃣.9️⃣, 🗄 👫 🌓 ⏬ ⚪️➡️
typing
🕹 - 🚶♀️ 🔗 🆎(Ⓜ) "🆎 🔢" ⚙️ ⬜ 🗜:
[
&]
🐍 3️⃣.9️⃣ ⚫️ 🔜:
my_list: list[str]
⏬ 🐍 ⏭ 3️⃣.9️⃣, ⚫️ 🔜:
from typing import List
my_list: List[str]
👈 🌐 🐩 🐍 ❕ 🆎 📄.
⚙️ 👈 🎏 🐩 ❕ 🏷 🔢 ⏮️ 🔗 🆎.
, 👆 🖼, 👥 💪 ⚒ tags
🎯 "📇 🎻":
=== "🐍 3️⃣.6️⃣ & 🔛"
```Python hl_lines="14"
{!> ../../../docs_src/body_nested_models/tutorial002.py!}
```
=== "🐍 3️⃣.9️⃣ & 🔛"
```Python hl_lines="14"
{!> ../../../docs_src/body_nested_models/tutorial002_py39.py!}
```
=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"
```Python hl_lines="12"
{!> ../../../docs_src/body_nested_models/tutorial002_py310.py!}
```
⚒ 🆎
✋️ ⤴️ 👥 💭 🔃 ⚫️, & 🤔 👈 🔖 🚫🔜 🚫 🔁, 👫 🔜 🎲 😍 🎻.
& 🐍 ✔️ 🎁 💽 🆎 ⚒ 😍 🏬, set
.
⤴️ 👥 💪 📣 tags
⚒ 🎻:
=== "🐍 3️⃣.6️⃣ & 🔛"
```Python hl_lines="1 14"
{!> ../../../docs_src/body_nested_models/tutorial003.py!}
```
=== "🐍 3️⃣.9️⃣ & 🔛"
```Python hl_lines="14"
{!> ../../../docs_src/body_nested_models/tutorial003_py39.py!}
```
=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"
```Python hl_lines="12"
{!> ../../../docs_src/body_nested_models/tutorial003_py310.py!}
```
⏮️ 👉, 🚥 👆 📨 📨 ⏮️ ❎ 📊, ⚫️ 🔜 🗜 ⚒ 😍 🏬.
& 🕐❔ 👆 🔢 👈 📊, 🚥 ℹ ✔️ ❎, ⚫️ 🔜 🔢 ⚒ 😍 🏬.
& ⚫️ 🔜 ✍ / 📄 ➡️ 💁♂️.
🐦 🏷
🔠 🔢 Pydantic 🏷 ✔️ 🆎.
✋️ 👈 🆎 💪 ⚫️ ➕1️⃣ Pydantic 🏷.
, 👆 💪 📣 🙇 🐦 🎻 "🎚" ⏮️ 🎯 🔢 📛, 🆎 & 🔬.
🌐 👈, 🎲 🐦.
🔬 📊
🖼, 👥 💪 🔬 Image
🏷:
=== "🐍 3️⃣.6️⃣ & 🔛"
```Python hl_lines="9-11"
{!> ../../../docs_src/body_nested_models/tutorial004.py!}
```
=== "🐍 3️⃣.9️⃣ & 🔛"
```Python hl_lines="9-11"
{!> ../../../docs_src/body_nested_models/tutorial004_py39.py!}
```
=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"
```Python hl_lines="7-9"
{!> ../../../docs_src/body_nested_models/tutorial004_py310.py!}
```
⚙️ 📊 🆎
& ⤴️ 👥 💪 ⚙️ ⚫️ 🆎 🔢:
=== "🐍 3️⃣.6️⃣ & 🔛"
```Python hl_lines="20"
{!> ../../../docs_src/body_nested_models/tutorial004.py!}
```
=== "🐍 3️⃣.9️⃣ & 🔛"
```Python hl_lines="20"
{!> ../../../docs_src/body_nested_models/tutorial004_py39.py!}
```
=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"
```Python hl_lines="18"
{!> ../../../docs_src/body_nested_models/tutorial004_py310.py!}
```
👉 🔜 ⛓ 👈 FastAPI 🔜 ⌛ 💪 🎏:
{
"name": "Foo",
"description": "The pretender",
"price": 42.0,
"tax": 3.2,
"tags": ["rock", "metal", "bar"],
"image": {
"url": "http://example.com/baz.jpg",
"name": "The Foo live"
}
}
🔄, 🤸 👈 📄, ⏮️ FastAPI 👆 🤚:
- 👨🎨 🐕🦺 (🛠️, ♒️), 🐦 🏷
- 💽 🛠️
- 💽 🔬
- 🏧 🧾
🎁 🆎 & 🔬
↖️ ⚪️➡️ 😐 ⭐ 🆎 💖 str
, int
, float
, ♒️. 👆 💪 ⚙️ 🌅 🏗 ⭐ 🆎 👈 😖 ⚪️➡️ str
.
👀 🌐 🎛 👆 ✔️, 🛒 🩺 Pydantic 😍 🆎. 👆 🔜 👀 🖼 ⏭ 📃.
🖼, Image
🏷 👥 ✔️ url
🏑, 👥 💪 📣 ⚫️ ↩️ str
, Pydantic HttpUrl
:
=== "🐍 3️⃣.6️⃣ & 🔛"
```Python hl_lines="4 10"
{!> ../../../docs_src/body_nested_models/tutorial005.py!}
```
=== "🐍 3️⃣.9️⃣ & 🔛"
```Python hl_lines="4 10"
{!> ../../../docs_src/body_nested_models/tutorial005_py39.py!}
```
=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"
```Python hl_lines="2 8"
{!> ../../../docs_src/body_nested_models/tutorial005_py310.py!}
```
🎻 🔜 ✅ ☑ 📛, & 📄 🎻 🔗 / 🗄 ✅.
🔢 ⏮️ 📇 📊
👆 💪 ⚙️ Pydantic 🏷 🏾 list
, set
, ♒️:
=== "🐍 3️⃣.6️⃣ & 🔛"
```Python hl_lines="20"
{!> ../../../docs_src/body_nested_models/tutorial006.py!}
```
=== "🐍 3️⃣.9️⃣ & 🔛"
```Python hl_lines="20"
{!> ../../../docs_src/body_nested_models/tutorial006_py39.py!}
```
=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"
```Python hl_lines="18"
{!> ../../../docs_src/body_nested_models/tutorial006_py310.py!}
```
👉 🔜 ⌛ (🗜, ✔, 📄, ♒️) 🎻 💪 💖:
{
"name": "Foo",
"description": "The pretender",
"price": 42.0,
"tax": 3.2,
"tags": [
"rock",
"metal",
"bar"
],
"images": [
{
"url": "http://example.com/baz.jpg",
"name": "The Foo live"
},
{
"url": "http://example.com/dave.jpg",
"name": "The Baz"
}
]
}
!!! info
👀 ❔ images
🔑 🔜 ✔️ 📇 🖼 🎚.
🙇 🐦 🏷
👆 💪 🔬 🎲 🙇 🐦 🏷:
=== "🐍 3️⃣.6️⃣ & 🔛"
```Python hl_lines="9 14 20 23 27"
{!> ../../../docs_src/body_nested_models/tutorial007.py!}
```
=== "🐍 3️⃣.9️⃣ & 🔛"
```Python hl_lines="9 14 20 23 27"
{!> ../../../docs_src/body_nested_models/tutorial007_py39.py!}
```
=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"
```Python hl_lines="7 12 18 21 25"
{!> ../../../docs_src/body_nested_models/tutorial007_py310.py!}
```
!!! info
👀 ❔ Offer
✔️ 📇 Item
Ⓜ, ❔ 🔄 ✔️ 📦 📇 Image
Ⓜ
💪 😁 📇
🚥 🔝 🎚 💲 🎻 💪 👆 ⌛ 🎻 array
(🐍 list
), 👆 💪 📣 🆎 🔢 🔢, 🎏 Pydantic 🏷:
images: List[Image]
⚖️ 🐍 3️⃣.9️⃣ & 🔛:
images: list[Image]
:
=== "🐍 3️⃣.6️⃣ & 🔛"
```Python hl_lines="15"
{!> ../../../docs_src/body_nested_models/tutorial008.py!}
```
=== "🐍 3️⃣.9️⃣ & 🔛"
```Python hl_lines="13"
{!> ../../../docs_src/body_nested_models/tutorial008_py39.py!}
```
👨🎨 🐕🦺 🌐
& 👆 🤚 👨🎨 🐕🦺 🌐.
🏬 🔘 📇:

👆 🚫 🚫 🤚 👉 😇 👨🎨 🐕🦺 🚥 👆 👷 🔗 ⏮️ dict
↩️ Pydantic 🏷.
✋️ 👆 🚫 ✔️ 😟 🔃 👫 👯♂️, 📨 #️⃣ 🗜 🔁 & 👆 🔢 🗜 🔁 🎻 💁♂️.
💪 ❌ dict
Ⓜ
👆 💪 📣 💪 dict
⏮️ 🔑 🆎 & 💲 🎏 🆎.
🍵 ✔️ 💭 ⏪ ⚫️❔ ☑ 🏑/🔢 📛 (🔜 💼 ⏮️ Pydantic 🏷).
👉 🔜 ⚠ 🚥 👆 💚 📨 🔑 👈 👆 🚫 ⏪ 💭.
🎏 ⚠ 💼 🕐❔ 👆 💚 ✔️ 🔑 🎏 🆎, ✅ int
.
👈 ⚫️❔ 👥 🔜 👀 📥.
👉 💼, 👆 🔜 🚫 🙆 dict
📏 ⚫️ ✔️ int
🔑 ⏮️ float
💲:
=== "🐍 3️⃣.6️⃣ & 🔛"
```Python hl_lines="9"
{!> ../../../docs_src/body_nested_models/tutorial009.py!}
```
=== "🐍 3️⃣.9️⃣ & 🔛"
```Python hl_lines="7"
{!> ../../../docs_src/body_nested_models/tutorial009_py39.py!}
```
!!! tip
✔️ 🤯 👈 🎻 🕴 🐕🦺 str
🔑.
✋️ Pydantic ✔️ 🏧 💽 🛠️.
👉 ⛓ 👈, ✋️ 👆 🛠️ 👩💻 💪 🕴 📨 🎻 🔑, 📏 👈 🎻 🔌 😁 🔢, Pydantic 🔜 🗜 👫 & ✔ 👫.
& `dict` 👆 📨 `weights` 🔜 🤙 ✔️ `int` 🔑 & `float` 💲.
🌃
⏮️ FastAPI 👆 ✔️ 🔆 💪 🚚 Pydantic 🏷, ⏪ 🚧 👆 📟 🙅, 📏 & 😍.
✋️ ⏮️ 🌐 💰:
- 👨🎨 🐕🦺 (🛠️ 🌐 ❗)
- 💽 🛠️ (.Ⓜ.. ✍ / 🛠️)
- 💽 🔬
- 🔗 🧾
- 🏧 🩺