You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

7.7 KiB

🔢

👆 💪 📣 ➡ "🔢" ⚖️ "🔢" ⏮️ 🎏 ⚙️ 🐍 📁 🎻:

{!../../../docs_src/path_params/tutorial001.py!}

💲🔢 item_id 🔜 🚶‍♀️ 👆 🔢 item_id.

, 🚥 👆 🏃 👉 🖼 & 🚶 http://127.0.0.1:8000/items/foo, 👆 🔜 👀 📨:

{"item_id":"foo"}

🔢 ⏮️ 🆎

👆 💪 📣 🆎🔢 🔢, ⚙️ 🐩 🐍 🆎 ✍:

{!../../../docs_src/path_params/tutorial002.py!}

👉 💼, item_id 📣 int.

!!! check 👉 🔜 🤝 👆 👨‍🎨 🐕‍🦺 🔘 👆 🔢, ⏮️ , 🛠️, ️.

💽 🛠️

🚥 👆 🏃 👉 🖼 & 📂 👆 🖥 http://127.0.0.1:8000/items/3, 👆 🔜 👀 📨:

{"item_id":3}

!!! check 👀 👈 💲 👆 🔢 📨 (& 📨) 3, 🐍 int, 🚫 🎻 "3".

, ⏮️ 👈 🆎 📄, **FastAPI** 🤝 👆 🏧 📨 <abbr title="converting the string that comes from an HTTP request into Python data">"✍"</abbr>.

💽 🔬

🚥 👆 🚶 🖥 http://127.0.0.1:8000/items/foo, 👆 🔜 👀 👌 🇺🇸🔍 :

{
    "detail": [
        {
            "loc": [
                "path",
                "item_id"
            ],
            "msg": "value is not a valid integer",
            "type": "type_error.integer"
        }
    ]
}

↩️🔢 item_id ✔️ 💲 "foo", 🚫 int.

🎏 🔜 😑 🚥 👆 🚚 float ↩️ int,: http://127.0.0.1:8000/items/4.2

!!! check , ⏮️ 🎏 🐍 🆎 📄, FastAPI 🤝 👆 💽 🔬.

👀 👈 ❌ 🎯 🇵🇸 ⚫️❔ ☝ 🌐❔ 🔬 🚫 🚶‍♀️.

👉 🙃 👍 ⏪ 🛠️ &amp; 🛠️ 📟 👈 🔗 ⏮️ 👆 🛠️.

🧾

& 🕐 👆 📂 👆 🖥 http://127.0.0.1:8000/docs, 👆 🔜 👀 🏧, 🎓, 🛠️ 🧾 💖:

!!! check 🔄, ⏮️ 👈 🎏 🐍 🆎 📄, FastAPI 🤝 👆 🏧, 🎓 🧾 (🛠️ 🦁 🎚).

👀 👈 ➡ 🔢 📣 🔢.

🐩-💰, 🎛 🧾

& ↩️ 🏗 🔗 ➡️ 🗄 🐩, 📤 📚 🔗 🧰.

↩️ 👉, FastAPI 🚚 🎛 🛠️ 🧾 (⚙️ 📄), 👆 💪 🔐 http://127.0.0.1:8000/redoc:

🎏 🌌, 📤 📚 🔗 🧰. 📟 🧰 📚 🇪🇸.

Pydantic

🌐 💽 🔬 🎭 🔽 🚘 Pydantic, 👆 🤚 🌐 💰 ➡️ ️. & 👆 💭 👆 👍 .

👆 💪 ⚙️ 🎏 🆎 📄 ⏮️ str, float, bool & 📚 🎏 🏗 📊 🆎.

📚 👫 🔬📃 🔰.

🤔

🕐 🏗 🛠️, 👆 💪 🔎🌐 👆 ✔️ 🔧 ➡.

💖 /users/me, ➡️ 💬 👈 🤚 📊 🔃 ⏮️ 👩‍💻.

& ⤴️ 👆 💪 ✔️/users/{user_id} 🤚 💽 🔃 🎯 👩‍💻 👩‍💻 🆔.

↩️ 🛠️ 🔬 ✔, 👆 💪💭 👈/users/me 📣1️⃣ /users/{user_id}:

{!../../../docs_src/path_params/tutorial003.py!}

, ➡ /users/{user_id} 🔜 🏏 /users/me, "💭" 👈 📨 🔢 user_id ⏮️ 💲 "me".

➡, 👆 🚫🔜 ↔ ➡ 🛠️:

{!../../../docs_src/path_params/tutorial003b.py!}

🥇 🕐 🔜 🕧 ⚙️ ↩️🏏 🥇.

🔁 💲

🚥 👆 ✔️ 🛠️ 👈 📨 🔢, 👆 💚 💪🔢 💲 🔁, 👆 💪 ⚙️ 🐩 🐍 Enum.

Enum 🎓

🗄 Enum & ✍ 🎧-🎓 👈 😖 ➡️ str & ➡️ Enum.

😖 ➡️ str 🛠️ 🩺 🔜 💪 💭 👈 💲 🔜 🆎 string & 🔜 💪 ✍ ☑.

⤴️🎓 🔢 ⏮️ 🔧 💲, 🔜 💪💲:

{!../../../docs_src/path_params/tutorial005.py!}

!!! info 🔢 (⚖️ 🔢) 💪 🐍 ↩️ 3️⃣.4️⃣.

!!! tip 🚥 👆 💭, "📊", "🎓", & "🍏" 📛 🎰 🏫 🏷.

📣 🔢

⤴️🔢 ⏮️ 🆎⚙️ 🔢 🎓 👆 ✍ (ModelName):

{!../../../docs_src/path_params/tutorial005.py!}

🩺

↩️ 💪 💲 🔢 🔢, 🎓 🩺 💪 🎦 👫 🎆:

👷 ⏮️ 🐍 🔢

💲 🔢 🔜 🔢 👨‍🎓.

🔬 🔢 👨‍🎓

👆 💪 🔬 ⏮️ 🔢 👨‍🎓 👆🔢 ModelName:

{!../../../docs_src/path_params/tutorial005.py!}

🤚 🔢 💲

👆 💪 🤚💲 ( str 👉 💼) ⚙️ model_name.value, ⚖️ 🏢, your_enum_member.value:

{!../../../docs_src/path_params/tutorial005.py!}

!!! tip 👆 💪 🔐 💲 "lenet" ⏮️ ModelName.lenet.value.

📨 🔢 👨‍🎓

👆 💪 📨 🔢 👨‍🎓 ➡️ 👆 🛠️, 🐦 🎻 💪 ( dict).

👫 🔜 🗜 👫 🔗 💲 (🎻 👉 💼) ⏭ 🛬 👫 👩‍💻:

{!../../../docs_src/path_params/tutorial005.py!}

👆 👩‍💻 👆 🔜 🤚 🎻 📨 💖:

{
  "model_name": "alexnet",
  "message": "Deep Learning FTW!"
}

🔢 ⚗ ➡

➡️ 💬 👆 ✔️ 🛠️ ⏮️/files/{file_path}.

👆 💪 file_path 🔌 , 💖 home/johndoe/myfile.txt.

, 📛 👈 📁 🔜 🕳 💖: /files/home/johndoe/myfile.txt.

🗄 🐕‍🦺

🗄 🚫 🐕‍🦺 🌌 📣 🔢 🔌 🔘, 👈 💪 ↘️ 😐 👈💯 & 🔬.

👐, 👆 💪 FastAPI, ⚙️ 1️⃣ 🔗 🧰 ➡️ 💃.

& 🩺 🔜 👷, 👐 🚫 🙆 🧾 💬 👈 🔢 🔜 🔌 ➡.

🔌

⚙️ 🎛 🔗 ➡️ 💃 👆 💪 📣 🔢 ⚙️ 📛 💖:

/files/{file_path:path}

👉 💼, 📛 🔢 file_path, & 🏁 🍕, :path, 💬 👈 🔢 🔜 🏏 🙆 .

, 👆 💪 ⚙️ ⏮️:

{!../../../docs_src/path_params/tutorial004.py!}

!!! tip 👆 💪 💪 🔢 🔌 /home/johndoe/myfile.txt, ⏮️ 🏁 🔪 (/).

👈 💼, 📛 🔜: `/files//home/johndoe/myfile.txt`, ⏮️ 2️⃣✖️ 🔪 (`//`) 🖖 `files` &amp; `home`.

🌃

⏮️ FastAPI, ⚙️ 📏, 🏋️ & 🐩 🐍 🆎 📄, 👆 🤚:

  • 👨‍🎨 🐕‍🦺: , ✍, ️.
  • 💽 ""
  • 💽 🔬
  • 🛠️ ✍ & 🏧 🧾

& 👆 🕴 ✔️ 📣 👫 🕐.

👈 🎲 👑 📈 FastAPI 🔬 🎛 🛠️ (↖️ ➡️ 🍣 🎭).