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.8 KiB

🔢 🔢 & 🎻 🔬

FastAPI👆 📣 🌖 ℹ & 🔬 👆 🔢.

➡️ 👉 🈸 🖼:

{* ../../docs_src/query_params_str_validations/tutorial001.py hl[9] *}

🔢 🔢 q 🆎 Union[str, None] (⚖️ str | None 🐍 3️⃣.1️⃣0️⃣), 👈👈 🆎 str 💪 None, & 👐, 🔢 💲 None, FastAPI 🔜 💭 🚫 ✔.

/// note

FastAPI 🔜 💭 👈 💲 q 🚫↩️ 🔢 💲 = None.

Union Union[str, None] 🔜👆 👨‍🎨 🤝 👆 👍 🐕‍🦺 & 🔍 .

///

🌖 🔬

👥 🔜 🛠️ 👈 q 📦, 🕐 🚚, 🚮 📐 🚫 📉 5️⃣0️⃣ 🦹.

🗄 Query

🏆 👈, 🥇 🗄 Query ➡️ fastapi:

{* ../../docs_src/query_params_str_validations/tutorial002.py hl[3] *}

⚙️ Query 🔢 💲

& 🔜 ⚙️ 🔢 💲 👆 🔢, ⚒ 🔢 max_length 5️⃣0️⃣:

{* ../../docs_src/query_params_str_validations/tutorial002.py hl[9] *}

👥 ✔️ 🔢 💲 None 🔢 ⏮️ Query(), 👥 💪 🔜🔢 💲 ⏮️ 🔢 Query(default=None), 🍦 🎏 🎯👈 🔢 💲.

:

q: Union[str, None] = Query(default=None)

...⚒ 🔢 📦, 🎏:

q: Union[str, None] = None

& 🐍 3️⃣.1️⃣0️⃣ & 🔛:

q: str | None = Query(default=None)

...⚒ 🔢 📦, 🎏:

q: str | None = None

📣 🎯 💆‍♂ 🔢 🔢.

/// info

✔️ 🤯 👈 🌅🍕🔢 📦 🍕:

= None

⚖️:

= Query(default=None)

🔜 ⚙️ 👈 None 🔢 💲, & 👈 🌌🔢 🚫.

Union[str, None] 🍕👆 👨‍🎨 🚚 👻 🐕‍🦺, 🚫 💬 FastAPI 👈 👉 🔢 🚫 ✔.

///

⤴️, 👥 💪 🚶‍♀️ 🌅 🔢 Query. 👉 💼, max_length 🔢 👈🎻:

q: Union[str, None] = Query(default=None, max_length=50)

👉 🔜📊, 🎦 🆑 🕐 📊 🚫 ☑, & 📄 🔢 🗄 🔗 🛠️.

🚮 🌅 🔬

👆 💪 🚮 🔢 min_length:

{* ../../docs_src/query_params_str_validations/tutorial003.py hl[10] *}

🚮 🥔 🧬

👆 💪 🔬 🥔 🧬 👈 🔢 🔜 🏏:

{* ../../docs_src/query_params_str_validations/tutorial004.py hl[11] *}

👉 🎯 🥔 🧬 👈 📨 🔢 💲:

  • ^: ▶️ ⏮️ 📄 🦹, 🚫 ✔️ 🦹 ⏭.
  • fixedquery: ✔️💲 fixedquery.
  • $: 🔚 📤, 🚫 ✔️ 🙆 🌖 🦹 ⏮️ fixedquery.

🚥 👆 💭 💸 ⏮️ 🌐 👉 "🥔 🧬" 💭, 🚫 😟. 👫 🏋️ 📚 👫👫. 👆 💪 📚 💩 🍵 💆‍♂ 🥔 🧬.

🕐 👆 💪 👫 & 🚶 & 💡 👫, 💭 👈 👆 💪 ⚙️ 👫 🔗 FastAPI.

🔢 💲

🎏 🌌 👈 👆 💪 🚶‍♀️ None 💲 default 🔢, 👆 💪 🚶‍♀️ 🎏 💲.

➡️ 💬 👈 👆 💚 📣 q 🔢 🔢 ✔️ min_length 3, & ✔️ 🔢 💲 "fixedquery":

{* ../../docs_src/query_params_str_validations/tutorial005.py hl[7] *}

/// note

✔️ 🔢 💲🔢 📦.

///

️ ✔

🕐 👥 🚫 💪 📣 🌅 🔬 ⚖️ 🗃, 👥 💪q 🔢 🔢🚫 📣 🔢 💲, 💖:

q: str

↩️:

q: Union[str, None] = None

👥 🔜 📣 ⏮️ Query, 🖼 💖:

q: Union[str, None] = Query(default=None, min_length=3)

, 🕐 👆 💪 📣 💲 ⚙️ Query, 👆 💪 🎯 🚫 📣 🔢 💲:

{* ../../docs_src/query_params_str_validations/tutorial006.py hl[7] *}

⏮️ None

👆 💪 📣 👈 🔢 💪 🚫 None, 👈 ️ ✔. 👉 🔜 👩‍💻 📨 💲, 🚥 💲 None.

👈, 👆 💪 📣 👈 None🆎 ⚙️ default=...:

{* ../../docs_src/query_params_str_validations/tutorial006c.py hl[9] *}

/// tip

Pydantic, 🏋️ 🌐 💽 🔬 & 🛠️ FastAPI, ✔️ 🎁 🎭 🕐 👆 ⚙️ Optional ⚖️ Union[Something, None] 🍵 🔢 💲, 👆 💪🌅 🔃 ️ Pydantic 🩺 🔃 ✔ 📦 🏑.

///

🔢 🔢 📇 / 💗 💲

🕐 👆 🔬 🔢 🔢 🎯 ⏮️ Query 👆 💪 📣 📨 📇 💲, ⚖️ 🙆‍♀ 🎏 🌌, 📨 💗 💲.

🖼, 📣 🔢 🔢 q 👈 💪 😑 💗 🕰 📛, 👆 💪 ✍:

{* ../../docs_src/query_params_str_validations/tutorial011.py hl[9] *}

⤴️, ⏮️ 📛 💖:

http://localhost:8000/items/?q=foo&q=bar

👆 🔜 📨 💗 q 🔢 🔢' 💲 (foo & bar) 🐍 list 🔘 👆 🛠️ 🔢, 🔢 🔢 q.

, 📨 👈 📛 🔜:

{
  "q": [
    "foo",
    "bar"
  ]
}

/// tip

📣 🔢 🔢 ⏮️ 🆎 list, 💖 🖼 🔛, 👆 💪 🎯 ⚙️ Query, 🔜 🔬 📨 💪.

///

🎓 🛠️ 🩺 🔜➡️, ✔ 💗 💲:

🔢 🔢 📇 / 💗 💲 ⏮️ 🔢

& 👆 💪 🔬 🔢 list 💲 🚥 👌 🚚:

{* ../../docs_src/query_params_str_validations/tutorial012.py hl[9] *}

🚥 👆 🚶:

http://localhost:8000/items/

🔢 q 🔜: ["foo", "bar"] & 👆 📨 🔜:

{
  "q": [
    "foo",
    "bar"
  ]
}

⚙️ list

👆 💪 ⚙️ list 🔗 ↩️ List[str] (⚖️ list[str] 🐍 3️⃣.9️⃣ ):

{* ../../docs_src/query_params_str_validations/tutorial013.py hl[7] *}

/// note

✔️ 🤯 👈 👉 💼, FastAPI 🏆 🚫 🎚 📇.

🖼, List[int] 🔜 (& 📄) 👈 🎚 📇 🔢. list 😞 🚫🔜.

///

📣 🌅 🗃

👆 💪 🚮 🌅🔃 🔢.

👈🔜 🔌 🏗 🗄 & ⚙️ 🧾 👩‍💻 🔢 & 🔢 🧰.

/// note

✔️ 🤯 👈 🎏 🧰 5️⃣📆 ✔️ 🎏 🎚 🗄 🐕‍🦺.

👫 💪 🚫 🎦 🌐 📣, 👐 🌅 💼, 📄 🛠️.

///

👆 💪 🚮 title:

{* ../../docs_src/query_params_str_validations/tutorial007.py hl[10] *}

& description:

{* ../../docs_src/query_params_str_validations/tutorial008.py hl[13] *}

📛 🔢

🌈 👈 👆 💚 🔢 item-query.

💖:

http://127.0.0.1:8000/items/?item-query=foobaritems

item-query 🚫🐍 🔢 📛.

🔐 🔜 item_query.

👆 💪 item-query...

⤴️ 👆 💪 📣 alias, & 👈 📛 🔜 ⚙️ 🔎 🔢 💲:

{* ../../docs_src/query_params_str_validations/tutorial009.py hl[9] *}

😛 🔢

🔜 ➡️ 💬 👆 🚫 💖 👉 🔢 🚫🔜.

👆 ✔️ 👈 📤 ↩️ 📤 👩‍💻 ⚙️ ️, 👆 💚 🩺 🎯 🎦 😢.

⤴️ 🚶‍♀️ 🔢 deprecated=True Query:

{* ../../docs_src/query_params_str_validations/tutorial010.py hl[18] *}

🩺 🔜 🎦 💖 👉:

🚫 ➡️ 🗄

🚫 🔢 🔢 ➡️ 🏗 🗄 🔗 (& ➡️, ➡️ 🏧 🧾 ⚙️), ⚒ 🔢 include_in_schema Query False:

{* ../../docs_src/query_params_str_validations/tutorial014.py hl[10] *}

🌃

👆 💪 📣 🌖 🔬 & 🗃 👆 🔢.

💊 🔬 & 🗃:

  • alias
  • title
  • description
  • deprecated

🔬 🎯 🎻:

  • min_length
  • max_length
  • regex

👫 🖼 👆 👀 📣 🔬 str 💲.

👀📃 👀 📣 🔬 🎏 🆎, 💖 🔢.