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.

3.4 KiB

📨 👔 📟

🎏 🌌 👆 💪📨 🏷, 👆 💪 📣 🇺🇸🔍 👔 📟 ⚙️ 📨 ⏮️ 🔢 status_code 🙆 🛠️:

  • @app.get()
  • @app.post()
  • @app.put()
  • @app.delete()
  • ️.
{!../../../docs_src/response_status_code/tutorial001.py!}

!!! note 👀 👈 status_code 🔢 "👨‍🎨" 👩‍🔬 (get, post, ️). 🚫 👆 🛠️ 🔢, 💖 🌐 🔢 & 💪.

status_code 🔢 📨 🔢 ⏮️ 🇺🇸🔍 👔 📟.

!!! info status_code 💪 👐 📨 IntEnum, 🐍 http.HTTPStatus.

🔜:

  • 📨 👈 👔 📟 📨.
  • 📄 🗄 🔗 ( & , 👩‍💻 🔢):

!!! note 📨 📟 (👀📄) 🎦 👈 📨 🔨 🚫 ✔️ 💪.

FastAPI 💭 👉, & 🔜 🏭 🗄 🩺 👈 🇵🇸 📤 🙅‍♂ 📨 💪.

🔃 🇺🇸🔍 👔 📟

!!! note 🚥 👆 💭 🇺🇸🔍 👔 📟, 🚶📄.

🇺🇸🔍, 👆 📨 🔢 👔 📟 3️⃣ 9️⃣ 🍕 📨.

👫 👔 📟 ✔️ 📛 🔗 🤔 👫, ️ ⚠ 🍕 🔢.

📏:

  • 100 & 🔛 "ℹ". 👆 🛎 ⚙️ 👫 🔗. 📨 ⏮️ 👫 👔 📟 🚫🔜 ✔️ 💪.
  • 200 & 🔛 "🏆" 📨. 👫 🕐 👆 🔜 ⚙️ 🏆.
    • 200 🔢 👔 📟, 🌐 "👌".
    • 1️⃣ 🖼 🔜 201, "✍". ️ 🛎 ⚙️ ⏮️ 🏗 🆕💽.
    • 🎁 💼 204, "🙅‍♂ 🎚". 👉 📨 ⚙️ 🕐 📤 🙅‍♂ 🎚 📨 👩‍💻, & 📨 🔜 🚫 ✔️ 💪.
  • 300 & 🔛 "". 📨 ⏮️ 👫 👔 📟 5️⃣📆 ⚖️ 5️⃣📆 🚫 ✔️ 💪, 🌖 304, "🚫 🔀", 🔜 🚫 ✔️ 1️⃣.
  • 400 & 🔛 "👩‍💻 " 📨. 👫 🥈 🆎 👆 🔜 🎲 ⚙️ 🏆.
    • 🖼 404, "🚫 🔎" 📨.
    • 💊 ➡️ 👩‍💻, 👆 💪 ⚙️ 400.
  • 500 & 🔛 💽 . 👆 🌖 🙅 ⚙️ 👫 🔗. 🕐 🕳 🚶 🍕 👆 🈸 📟, ⚖️ 💽, 🔜 🔁 📨 1️⃣ 👫 👔 📟.

!!! tip 💭 🌅 🔃 🔠 👔 📟 & 📟 , 🏇 🧾 🔃 🇺🇸🔍 👔 📟.

💭 📛

➡️ 👀 ⏮️ 🖼 🔄:

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

201 👔 📟 "✍".

👆 🚫 ✔️ 🔠 👉 📟 ⛓.

👆 💪 ⚙️ 🏪 🔢 ➡️ fastapi.status.

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

👫 🏪, 👫 🧑‍🤝‍🧑 🎏 🔢, 👈 🌌 👆 💪 ⚙️ 👨‍🎨 📋 🔎 👫:

!!! note "📡 ℹ" 👆 💪 ⚙️ from starlette import status.

**FastAPI** 🚚 🎏 `starlette.status` `fastapi.status` 🏪 👆, 👩‍💻. ✋️ ⚫️ 👟 🔗 ⚪️➡️ 💃.

🔀 🔢

, 🏧 👩‍💻 🦮{.internal-link target=_blank}, 👆 🔜 👀 📨 🎏 👔 📟 🌘 🔢 👆 📣 📥.