diff --git a/docs/zh-hant/docs/index.md b/docs/zh-hant/docs/index.md index 1111d427ce..e2e6c1e8a2 100644 --- a/docs/zh-hant/docs/index.md +++ b/docs/zh-hant/docs/index.md @@ -5,10 +5,10 @@

- FastAPI + FastAPI

- FastAPI 框架,高效能,易於學習,快速開發,適用於生產環境 + FastAPI 框架,高效能,易於學習,快速撰寫程式碼,適用於生產環境

@@ -27,7 +27,7 @@ --- -**文件**: https://fastapi.tiangolo.com +**文件**: https://fastapi.tiangolo.com **原始碼**: https://github.com/fastapi/fastapi @@ -40,7 +40,7 @@ FastAPI 是一個現代、快速(高效能)的 Web 框架,用於以 Python * **快速**: 非常高的效能,可與 **NodeJS** 和 **Go** 效能相當(歸功於 Starlette 和 Pydantic)。[可用的最快 Python 框架之一](#performance)。 * **快速撰寫程式碼**: 提高開發功能的速度約 200% 至 300%。 * * **更少的 Bug**: 減少約 40% 的人為(開發者)導致的錯誤。 * -* **直覺**: 具有出色的編輯器支援。處處都有Completion。更少的除錯時間。 +* **直覺**: 具有出色的編輯器支援。處處都有Completion。更少的除錯時間。 * **簡單**: 設計上易於使用和學習。更少的閱讀文件時間。 * **簡潔**: 最小化程式碼重複性。每個參數宣告即可獲得多項功能。更少的 Bug。 * **穩健**: 立即獲得可用於生產環境的程式碼,並有自動生成的互動式文件。 @@ -69,7 +69,7 @@ FastAPI 是一個現代、快速(高效能)的 Web 框架,用於以 Python -其他贊助商 +其他贊助商 ## 評價 { #opinions } @@ -127,7 +127,7 @@ FastAPI 是一個現代、快速(高效能)的 Web 框架,用於以 Python -如果你不是在開發 Web API,而是在開發一個要在終端機中使用的 CLI 應用程式,不妨試試 **Typer**。 +如果你不是在開發 Web API,而是在開發一個要在終端機中使用的 CLI app,不妨試試 **Typer**。 **Typer** 是 FastAPI 的小兄弟,並且旨在成為 **CLI 的 FastAPI**。 ⌨️ 🚀 @@ -140,7 +140,7 @@ FastAPI 是站在以下巨人的肩膀上: ## 安裝 { #installation } -建立並啟用一個 虛擬環境,然後安裝 FastAPI: +建立並啟用一個 虛擬環境,然後安裝 FastAPI:

@@ -161,8 +161,6 @@ $ pip install "fastapi[standard]" 建立一個檔案 `main.py`,內容如下: ```Python -from typing import Union - from fastapi import FastAPI app = FastAPI() @@ -174,7 +172,7 @@ def read_root(): @app.get("/items/{item_id}") -def read_item(item_id: int, q: Union[str, None] = None): +def read_item(item_id: int, q: str | None = None): return {"item_id": item_id, "q": q} ``` @@ -183,9 +181,7 @@ def read_item(item_id: int, q: Union[str, None] = None): 如果你的程式使用 `async` / `await`,請使用 `async def`: -```Python hl_lines="9 14" -from typing import Union - +```Python hl_lines="7 12" from fastapi import FastAPI app = FastAPI() @@ -197,13 +193,13 @@ async def read_root(): @app.get("/items/{item_id}") -async def read_item(item_id: int, q: Union[str, None] = None): +async def read_item(item_id: int, q: str | None = None): return {"item_id": item_id, "q": q} ``` **注意**: -如果你不確定,請查看文件中 _"In a hurry?"_ 章節關於 `async` 和 `await` 的說明。 +如果你不確定,請查看文件中 _"In a hurry?"_ 章節關於 `async` 和 `await` 的說明。 @@ -245,7 +241,7 @@ INFO: Application startup complete. 預設情況下,`fastapi dev` 會啟用自動重新載入,方便本機開發。 -你可以在 FastAPI CLI 文件 了解更多。 +你可以在 FastAPI CLI 文件 了解更多。 @@ -288,9 +284,7 @@ INFO: Application startup complete. 藉由 Pydantic,你可以使用標準 Python 型別來宣告 body。 -```Python hl_lines="4 9-12 25-27" -from typing import Union - +```Python hl_lines="2 7-10 23-25" from fastapi import FastAPI from pydantic import BaseModel @@ -300,7 +294,7 @@ app = FastAPI() class Item(BaseModel): name: str price: float - is_offer: Union[bool, None] = None + is_offer: bool | None = None @app.get("/") @@ -309,7 +303,7 @@ def read_root(): @app.get("/items/{item_id}") -def read_item(item_id: int, q: Union[str, None] = None): +def read_item(item_id: int, q: str | None = None): return {"item_id": item_id, "q": q} @@ -369,12 +363,12 @@ item: Item ...透過這一次宣告,你將獲得: * 編輯器支援,包含: - * 自動補全。 + * Completion。 * 型別檢查。 * 資料驗證: * 當資料無效時,自動且清楚地回報錯誤。 * 即使是深層巢狀的 JSON 物件也能驗證。 -* Conversion輸入資料:將來自網路的資料轉換為 Python 資料與型別。可從以下讀取: +* Conversion輸入資料:將來自網路的資料轉換為 Python 資料與型別。可從以下讀取: * JSON。 * 路徑參數。 * 查詢參數。 @@ -382,7 +376,7 @@ item: Item * Headers。 * Forms。 * Files。 -* Conversion輸出資料:將 Python 資料與型別轉換為網路資料(JSON): +* Conversion輸出資料:將 Python 資料與型別轉換為網路資料(JSON): * 轉換 Python 型別(`str`、`int`、`float`、`bool`、`list` 等)。 * `datetime` 物件。 * `UUID` 物件。 @@ -445,7 +439,7 @@ item: Item * 從不同位置宣告**參數**,例如:**headers**、**cookies**、**form 欄位**和**檔案**。 * 如何設定 **驗證限制**,例如 `maximum_length` 或 `regex`。 -* 強大且易用的 **Dependency Injection** 系統。 +* 強大且易用的 **Dependency Injection** 系統。 * 安全性與身份驗證,包含支援 **OAuth2**、**JWT tokens** 與 **HTTP Basic** 驗證。 * 更進階(但同樣簡單)的技巧,用於宣告**深層巢狀的 JSON models**(歸功於 Pydantic)。 * 與 Strawberry 及其他函式庫的 **GraphQL** 整合。 @@ -458,7 +452,7 @@ item: Item ### 部署你的 app(可選) { #deploy-your-app-optional } -你也可以選擇將 FastAPI app 部署到 FastAPI Cloud;如果你還沒加入候補名單,可以前往加入。 🚀 +你也可以選擇將 FastAPI app 部署到 FastAPI Cloud,如果你還沒加入候補名單,請前往加入。 🚀 如果你已經有 **FastAPI Cloud** 帳號(我們已從候補名單邀請你 😉),你可以用一個指令部署你的應用程式。 @@ -530,7 +524,7 @@ FastAPI 依賴 Pydantic 與 Starlette。 * httpx - 若你想使用 `TestClient`,則必須安裝。 * jinja2 - 若你想使用預設的 template 設定,則必須安裝。 -* python-multipart - 若你想透過 `request.form()` 支援表單 "parsing",則必須安裝。 +* python-multipart - 若你想透過 `request.form()` 支援表單 "parsing",則必須安裝。 由 FastAPI 使用: