From 26a7f8a6f586a691513131fa2c9001cadbfc6514 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 20 Mar 2026 15:17:43 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=90=20Update=20translations=20for=20zh?= =?UTF-8?q?-hant=20(update-outdated)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh-hant/docs/_llm-test.md | 18 +-- docs/zh-hant/docs/alternatives.md | 60 ++++----- docs/zh-hant/docs/async.md | 18 +-- docs/zh-hant/docs/benchmarks.md | 2 +- docs/zh-hant/docs/environment-variables.md | 10 +- docs/zh-hant/docs/fastapi-cli.md | 71 ++++++++-- docs/zh-hant/docs/features.md | 26 ++-- docs/zh-hant/docs/help-fastapi.md | 58 ++++----- docs/zh-hant/docs/history-design-future.md | 14 +- docs/zh-hant/docs/index.md | 122 ++++++++---------- docs/zh-hant/docs/project-generation.md | 2 +- docs/zh-hant/docs/python-types.md | 10 +- .../docs/tutorial/bigger-applications.md | 47 +++++-- docs/zh-hant/docs/tutorial/body-updates.md | 6 +- docs/zh-hant/docs/tutorial/cors.md | 8 +- docs/zh-hant/docs/tutorial/debugging.md | 4 +- docs/zh-hant/docs/tutorial/encoder.md | 4 +- .../zh-hant/docs/tutorial/extra-data-types.md | 4 +- docs/zh-hant/docs/tutorial/extra-models.md | 6 +- docs/zh-hant/docs/tutorial/first-steps.md | 75 +++++++++-- docs/zh-hant/docs/tutorial/handling-errors.md | 2 +- docs/zh-hant/docs/tutorial/index.md | 22 ++-- docs/zh-hant/docs/tutorial/middleware.md | 10 +- docs/zh-hant/docs/tutorial/path-params.md | 16 +-- .../tutorial/query-params-str-validations.md | 6 +- docs/zh-hant/docs/tutorial/request-forms.md | 6 +- docs/zh-hant/docs/tutorial/response-model.md | 9 +- .../docs/tutorial/response-status-code.md | 6 +- docs/zh-hant/docs/virtual-environments.md | 28 ++-- 29 files changed, 398 insertions(+), 272 deletions(-) diff --git a/docs/zh-hant/docs/_llm-test.md b/docs/zh-hant/docs/_llm-test.md index 85cfd22991..f4c1efca82 100644 --- a/docs/zh-hant/docs/_llm-test.md +++ b/docs/zh-hant/docs/_llm-test.md @@ -11,7 +11,7 @@ * 檢查翻譯是否正確。 * 如有需要,改進你的語言特定提示、通用提示,或英文原文。 * 然後手動修正翻譯中剩下的問題,讓它成為一個好的譯文。 -* 重新翻譯,並保留這份好的譯文。理想結果是 LLM 不再對該譯文做任何變更。這代表通用提示與你的語言特定提示已經盡可能完善(有時它仍可能做出幾個看似隨機的變更,原因是LLMs 並非決定性演算法)。 +* 重新翻譯,並保留這份好的譯文。理想結果是 LLM 不再對該譯文做任何變更。這代表通用提示與你的語言特定提示已經盡可能完善(有時它仍可能做出幾個看似隨機的變更,原因是[LLMs 並非決定性演算法](https://doublespeak.chat/#/handbook#deterministic-output))。 測試: @@ -95,7 +95,7 @@ $ fastapi run 外部連結 -* 連結到樣式 -* 連結到腳本 -* 連結到圖片 +* [內部連結](index.md#installation) +* [外部連結](https://sqlmodel.tiangolo.com/) +* [連結到樣式](https://fastapi.tiangolo.com/css/styles.css) +* [連結到腳本](https://fastapi.tiangolo.com/js/logic.js) +* [連結到圖片](https://fastapi.tiangolo.com/img/foo.jpg) 連結文字應被翻譯,連結位址應指向對應的翻譯版本: -* FastAPI 連結 +* [FastAPI 連結](https://fastapi.tiangolo.com/zh-hant/) //// @@ -291,7 +291,7 @@ Hello again. * 即時 * 標準 * 預設 -* 區分大小寫 +* 区分大小寫 * 不區分大小寫 * 提供應用程式服務 diff --git a/docs/zh-hant/docs/alternatives.md b/docs/zh-hant/docs/alternatives.md index 340c47d8ba..ee99faf99f 100644 --- a/docs/zh-hant/docs/alternatives.md +++ b/docs/zh-hant/docs/alternatives.md @@ -14,7 +14,7 @@ ## 先前的工具 { #previous-tools } -### Django { #django } +### [Django](https://www.djangoproject.com/) { #django } 它是最受歡迎且廣受信任的 Python 框架。像 Instagram 等系統就是用它打造的。 @@ -22,7 +22,7 @@ 它一開始是為在後端產生 HTML 而設計,而非為了建立提供現代前端(如 React、Vue.js、Angular)或其他系統(如 IoT 裝置)使用的 API。 -### Django REST Framework { #django-rest-framework } +### [Django REST Framework](https://www.django-rest-framework.org/) { #django-rest-framework } Django REST framework 的目標是成為一套在 Django 之上構建 Web API 的彈性工具組,以強化其 API 能力。 @@ -30,7 +30,7 @@ Django REST framework 的目標是成為一套在 Django 之上構建 Web API 它是「自動 API 文件」的早期典範之一,而這正是啟發我「尋找」**FastAPI** 的第一個想法。 -/// note | 注意 +/// note Django REST Framework 由 Tom Christie 創建。他同時也是 Starlette 與 Uvicorn 的作者,而 **FastAPI** 就是建立在它們之上。 @@ -42,7 +42,7 @@ Django REST Framework 由 Tom Christie 創建。他同時也是 Starlette 與 Uv /// -### Flask { #flask } +### [Flask](https://flask.palletsprojects.com) { #flask } Flask 是一個「微框架」,它不包含資料庫整合,也沒有像 Django 那樣內建許多功能。 @@ -64,7 +64,7 @@ Flask 是一個「微框架」,它不包含資料庫整合,也沒有像 Djan /// -### Requests { #requests } +### [Requests](https://requests.readthedocs.io) { #requests } **FastAPI** 其實不是 **Requests** 的替代品。兩者的範疇截然不同。 @@ -106,7 +106,7 @@ def read_url(): /// -### Swagger / OpenAPI { #swagger-openapi } +### [Swagger](https://swagger.io/) / [OpenAPI](https://github.com/OAI/OpenAPI-Specification/) { #swagger-openapi } 我想從 Django REST Framework 得到的主要功能是自動 API 文件。 @@ -124,8 +124,8 @@ def read_url(): 並整合基於標準的使用者介面工具: -* Swagger UI -* ReDoc +* [Swagger UI](https://github.com/swagger-api/swagger-ui) +* [ReDoc](https://github.com/Rebilly/ReDoc) 選擇這兩個是因為它們相當受歡迎且穩定,但稍加搜尋,你會發現有數十種 OpenAPI 的替代使用者介面(都能與 **FastAPI** 一起使用)。 @@ -135,7 +135,7 @@ def read_url(): 有幾個 Flask 的 REST 框架,但在投入時間調查後,我發現許多已停止維護或被棄置,且存在一些關鍵問題使之不適用。 -### Marshmallow { #marshmallow } +### [Marshmallow](https://marshmallow.readthedocs.io/en/stable/) { #marshmallow } API 系統需要的主要功能之一是資料「序列化」,也就是把程式中的資料(Python)轉成能透過網路傳輸的形式。例如,將含有資料庫資料的物件轉成 JSON 物件、把 `datetime` 物件轉成字串等等。 @@ -153,7 +153,7 @@ API 需要的另一個重要功能是資料驗證,確保資料在特定條件 /// -### Webargs { #webargs } +### [Webargs](https://webargs.readthedocs.io/en/latest/) { #webargs } API 所需的另一項大功能,是從傳入請求中解析資料。 @@ -175,7 +175,7 @@ Webargs 由與 Marshmallow 相同的開發者創建。 /// -### APISpec { #apispec } +### [APISpec](https://apispec.readthedocs.io/en/stable/) { #apispec } Marshmallow 與 Webargs 以外掛提供驗證、解析與序列化。 @@ -205,7 +205,7 @@ APISpec 由與 Marshmallow 相同的開發者創建。 /// -### Flask-apispec { #flask-apispec } +### [Flask-apispec](https://flask-apispec.readthedocs.io/en/latest/) { #flask-apispec } 這是一個 Flask 外掛,把 Webargs、Marshmallow 與 APISpec 串在一起。 @@ -219,11 +219,11 @@ APISpec 由與 Marshmallow 相同的開發者創建。 使用它促成了數個 Flask 全端(full-stack)產生器。這些是我(以及若干外部團隊)至今主要使用的技術組合: -* https://github.com/tiangolo/full-stack -* https://github.com/tiangolo/full-stack-flask-couchbase -* https://github.com/tiangolo/full-stack-flask-couchdb +* [https://github.com/tiangolo/full-stack](https://github.com/tiangolo/full-stack) +* [https://github.com/tiangolo/full-stack-flask-couchbase](https://github.com/tiangolo/full-stack-flask-couchbase) +* [https://github.com/tiangolo/full-stack-flask-couchdb](https://github.com/tiangolo/full-stack-flask-couchdb) -而這些全端產生器,也成為了 [**FastAPI** 專案產生器](project-generation.md){.internal-link target=_blank} 的基礎。 +而這些全端產生器,也成為了 [**FastAPI** 專案產生器](project-generation.md) 的基礎。 /// info @@ -237,7 +237,7 @@ Flask-apispec 由與 Marshmallow 相同的開發者創建。 /// -### NestJS(與 Angular) { #nestjs-and-angular } +### [NestJS](https://nestjs.com/)(與 [Angular](https://angular.io/)) { #nestjs-and-angular } 這甚至不是 Python。NestJS 是受 Angular 啟發的 JavaScript(TypeScript)NodeJS 框架。 @@ -259,13 +259,13 @@ Flask-apispec 由與 Marshmallow 相同的開發者創建。 /// -### Sanic { #sanic } +### [Sanic](https://sanic.readthedocs.io/en/latest/) { #sanic } 它是最早基於 `asyncio` 的極高速 Python 框架之一,並做得很像 Flask。 /// note | 技術細節 -它使用 `uvloop` 取代預設的 Python `asyncio` 事件圈。這也是它如此之快的原因。 +它使用 [`uvloop`](https://github.com/MagicStack/uvloop) 取代預設的 Python `asyncio` 事件圈。這也是它如此之快的原因。 它明顯啟發了 Uvicorn 與 Starlette,而在公開的基準測試中,它們目前比 Sanic 更快。 @@ -279,7 +279,7 @@ Flask-apispec 由與 Marshmallow 相同的開發者創建。 /// -### Falcon { #falcon } +### [Falcon](https://falconframework.org/) { #falcon } Falcon 是另一個高效能 Python 框架,設計上極簡,並作為其他框架(如 Hug)的基礎。 @@ -297,7 +297,7 @@ Falcon 是另一個高效能 Python 框架,設計上極簡,並作為其他 /// -### Molten { #molten } +### [Molten](https://moltenframework.com/) { #molten } 我在 **FastAPI** 打造的早期發現了 Molten。它有一些相當類似的想法: @@ -321,7 +321,7 @@ Falcon 是另一個高效能 Python 框架,設計上極簡,並作為其他 /// -### Hug { #hug } +### [Hug](https://github.com/hugapi/hug) { #hug } Hug 是最早使用 Python 型別提示來宣告 API 參數型別的框架之一。這是個很棒的點子,也啟發了其他工具。 @@ -337,7 +337,7 @@ Hug 是最早使用 Python 型別提示來宣告 API 參數型別的框架之一 /// info -Hug 由 Timothy Crosley 創建,他同時也是 `isort` 的作者,一個自動排序 Python 匯入的好工具。 +Hug 由 Timothy Crosley 創建,他同時也是 [`isort`](https://github.com/timothycrosley/isort) 的作者,一個自動排序 Python 匯入的好工具。 /// @@ -351,7 +351,7 @@ Hug 啟發 **FastAPI** 在函式中宣告 `response` 參數以設定標頭與 Co /// -### APIStar (<= 0.5) { #apistar-0-5 } +### [APIStar](https://github.com/encode/apistar) (<= 0.5) { #apistar-0-5 } 在決定打造 **FastAPI** 之前,我找到了 **APIStar** 伺服器。它幾乎具備我所尋找的一切,而且設計很出色。 @@ -401,7 +401,7 @@ APIStar 由 Tom Christie 創建。他也創建了: ## **FastAPI** 所採用的工具 { #used-by-fastapi } -### Pydantic { #pydantic } +### [Pydantic](https://docs.pydantic.dev/) { #pydantic } Pydantic 是基於 Python 型別提示,定義資料驗證、序列化與文件(使用 JSON Schema)的函式庫。 @@ -417,7 +417,7 @@ Pydantic 是基於 Python 型別提示,定義資料驗證、序列化與文件 /// -### Starlette { #starlette } +### [Starlette](https://www.starlette.dev/) { #starlette } Starlette 是一個輕量的 ASGI 框架/工具集,非常適合用來建構高效能的 asyncio 服務。 @@ -458,11 +458,11 @@ ASGI 是由 Django 核心團隊成員正在開發的新「標準」。它尚未 `FastAPI` 這個類別本身直接繼承自 `Starlette` 類別。 -因此,凡是你能用 Starlette 做的事,你幾乎都能直接用 **FastAPI** 完成,因為它基本上就是加強版的 Starlette。 +因此,凡是你能用 Starlette 做的事,你都能直接用 **FastAPI** 完成,因為它基本上就是加強版的 Starlette。 /// -### Uvicorn { #uvicorn } +### [Uvicorn](https://www.uvicorn.dev/) { #uvicorn } Uvicorn 是基於 uvloop 與 httptools 的極速 ASGI 伺服器。 @@ -476,10 +476,10 @@ Uvicorn 是基於 uvloop 與 httptools 的極速 ASGI 伺服器。 你也可以使用 `--workers` 命令列選項,取得非同步的多製程伺服器。 -更多細節請見[部署](deployment/index.md){.internal-link target=_blank}章節。 +更多細節請見[部署](deployment/index.md)章節。 /// ## 效能與速度 { #benchmarks-and-speed } -想了解、比較並看出 Uvicorn、Starlette 與 FastAPI 之間的差異,請參考[效能評測](benchmarks.md){.internal-link target=_blank}。 +想了解、比較並看出 Uvicorn、Starlette 與 FastAPI 之間的差異,請參考[效能評測](benchmarks.md)。 diff --git a/docs/zh-hant/docs/async.md b/docs/zh-hant/docs/async.md index a03d71815f..c3c67aa24b 100644 --- a/docs/zh-hant/docs/async.md +++ b/docs/zh-hant/docs/async.md @@ -141,7 +141,7 @@ def results(): /// info -漂亮的插畫來自 Ketrina Thompson. 🎨 +漂亮的插畫來自 [Ketrina Thompson](https://www.instagram.com/ketrinadrawsalot)。 🎨 /// @@ -207,7 +207,7 @@ def results(): /// info -漂亮的插畫來自 Ketrina Thompson. 🎨 +漂亮的插畫來自 [Ketrina Thompson](https://www.instagram.com/ketrinadrawsalot)。 🎨 /// @@ -245,13 +245,13 @@ def results(): 這種「等待」 🕙 通常以微秒來衡量,但累加起來,最終還是花費了很多等待時間。 -這就是為什麼對於 Web API 來說,使用非同步程式碼 ⏸🔀⏯ 是非常有意義的。 +這就是為什麼對於 Web API 來說,使用非同步程式碼 ⏸🔀⏯ 是非常有意味的。 這種類型的非同步性正是 NodeJS 成功的原因(儘管 NodeJS 不是平行的),這也是 Go 語言作為程式語言的一個強大優勢。 這與 **FastAPI** 所能提供的性能水平相同。 -你可以同時利用並行性和平行性,進一步提升效能,這比大多數已測試的 NodeJS 框架都更快,並且與 Go 語言相當,而 Go 是一種更接近 C 的編譯語言(感謝 Starlette)。 +你可以同時利用並行性和平行性,進一步提升效能,這比大多數已測試的 NodeJS 框架都更快,並且與 Go 語言相當,而 Go 是一種更接近 C 的編譯語言([感謝 Starlette](https://www.techempower.com/benchmarks/#section=data-r17&hw=ph&test=query&l=zijmkf-1))。 ### 並行比平行更好嗎? { #is-concurrency-better-than-parallelism } @@ -363,13 +363,13 @@ async def read_burgers(): ### 編寫自己的非同步程式碼 { #write-your-own-async-code } -Starlette(和 **FastAPI**)是基於 AnyIO 實作的,這使得它們與 Python 標準函式庫 asyncioTrio 相容。 +Starlette(和 **FastAPI**)是基於 [AnyIO](https://anyio.readthedocs.io/en/stable/) 實作的,這使得它們與 Python 標準函式庫 [asyncio](https://docs.python.org/3/library/asyncio-task.html) 和 [Trio](https://trio.readthedocs.io/en/stable/) 相容。 -特別是,你可以直接使用 AnyIO 來處理更複雜的並行使用案例,這些案例需要你在自己的程式碼中使用更高階的模式。 +特別是,你可以直接使用 [AnyIO](https://anyio.readthedocs.io/en/stable/) 來處理更複雜的並行使用案例,這些案例需要你在自己的程式碼中使用更高階的模式。 -即使你不使用 **FastAPI**,你也可以使用 AnyIO 來撰寫自己的非同步應用程式,並獲得高相容性及一些好處(例如「結構化並行」)。 +即使你不使用 **FastAPI**,你也可以使用 [AnyIO](https://anyio.readthedocs.io/en/stable/) 來撰寫自己的非同步應用程式,並獲得高相容性及一些好處(例如「結構化並行」)。 -我另外在 AnyIO 之上做了一個薄封裝的函式庫,稍微改進型別註解以獲得更好的**自動補全**、**即時錯誤**等。同時它也提供友善的介紹與教學,幫助你**理解**並撰寫**自己的非同步程式碼**:Asyncer。當你需要**將非同步程式碼與一般**(阻塞/同步)**程式碼整合**時,它特別實用。 +我另外在 AnyIO 之上做了一個薄封裝的函式庫,稍微改進型別註解以獲得更好的**自動補全**、**即時錯誤**等。同時它也提供友善的介紹與教學,幫助你**理解**並撰寫**自己的非同步程式碼**:[Asyncer](https://asyncer.tiangolo.com/)。當你需要**將非同步程式碼與一般**(阻塞/同步)**程式碼整合**時,它特別實用。 ### 其他形式的非同步程式碼 { #other-forms-of-asynchronous-code } @@ -381,7 +381,7 @@ Starlette(和 **FastAPI**)是基於 Gevent。但這些程式碼要更難以理解、調試和思考。 +在較舊的 Python 版本中,你可能會使用多執行緒或 [Gevent](https://www.gevent.org/)。但這些程式碼要更難以理解、調試和思考。 在較舊的 NodeJS / 瀏覽器 JavaScript 中,你會使用「回呼」,這可能會導致“回呼地獄”。 diff --git a/docs/zh-hant/docs/benchmarks.md b/docs/zh-hant/docs/benchmarks.md index c5b76700b3..2b5b3f7ee1 100644 --- a/docs/zh-hant/docs/benchmarks.md +++ b/docs/zh-hant/docs/benchmarks.md @@ -1,6 +1,6 @@ # 基準測試 { #benchmarks } -由第三方機構 TechEmpower 的基準測試表明在 Uvicorn 下運行的 **FastAPI** 應用程式是 最快的 Python 可用框架之一,僅次於 Starlette 和 Uvicorn 本身(於 FastAPI 內部使用)。 +由第三方機構 TechEmpower 的基準測試表明在 Uvicorn 下運行的 **FastAPI** 應用程式是 [最快的 Python 可用框架之一](https://www.techempower.com/benchmarks/#section=test&runid=7464e520-0dc2-473d-bd34-dbdfd7e85911&hw=ph&test=query&l=zijzen-7),僅次於 Starlette 和 Uvicorn 本身(於 FastAPI 內部使用)。 但是在查看基準得分和對比時,請注意以下幾點。 diff --git a/docs/zh-hant/docs/environment-variables.md b/docs/zh-hant/docs/environment-variables.md index 5b684b9e6a..09264b7e26 100644 --- a/docs/zh-hant/docs/environment-variables.md +++ b/docs/zh-hant/docs/environment-variables.md @@ -65,7 +65,7 @@ print(f"Hello {name} from Python") /// tip -第二個參數是 `os.getenv()` 的預設回傳值。 +第二個參數是 [`os.getenv()`](https://docs.python.org/3.8/library/os.html#os.getenv) 的預設回傳值。 如果沒有提供,預設值為 `None`,這裡我們提供 `"World"` 作為預設值。 @@ -153,7 +153,7 @@ Hello World from Python /// tip -你可以在 The Twelve-Factor App: 配置中了解更多資訊。 +你可以在 [The Twelve-Factor App: 配置](https://12factor.net/config) 中了解更多資訊。 /// @@ -163,7 +163,7 @@ Hello World from Python 這意味著從環境變數中讀取的**任何值**在 Python 中都將是一個 `str`,任何型別轉換或驗證都必須在程式碼中完成。 -你將在[進階使用者指南 - 設定和環境變數](./advanced/settings.md){.internal-link target=_blank}中了解更多關於使用環境變數處理**應用程式設定**的資訊。 +你將在[進階使用者指南 - 設定和環境變數](./advanced/settings.md)中了解更多關於使用環境變數處理**應用程式設定**的資訊。 ## `PATH` 環境變數 { #path-environment-variable } @@ -285,13 +285,13 @@ $ C:\opt\custompython\bin\python //// -當學習[虛擬環境](virtual-environments.md){.internal-link target=_blank}時,這些資訊將會很有用。 +當學習[虛擬環境](virtual-environments.md)時,這些資訊將會很有用。 ## 結論 { #conclusion } 透過這個教學,你應該對**環境變數**是什麼以及如何在 Python 中使用它們有了基本的了解。 -你也可以在 環境變數的維基百科條目 中閱讀更多。 +你也可以在 [環境變數的維基百科條目](https://en.wikipedia.org/wiki/Environment_variable) 中閱讀更多。 在許多情況下,環境變數的用途和適用性可能不會立刻顯現。但是在開發過程中,它們會在許多不同的場景中出現,因此瞭解它們是非常必要的。 diff --git a/docs/zh-hant/docs/fastapi-cli.md b/docs/zh-hant/docs/fastapi-cli.md index 57b5ec98f2..931b604c59 100644 --- a/docs/zh-hant/docs/fastapi-cli.md +++ b/docs/zh-hant/docs/fastapi-cli.md @@ -1,15 +1,15 @@ # FastAPI CLI { #fastapi-cli } -**FastAPI CLI** 是一個命令列程式,能用來運行你的 FastAPI 應用程式、管理你的 FastAPI 專案等。 +**FastAPI CLI** 是一個命令列程式,你可以用它來啟動你的 FastAPI 應用程式、管理你的 FastAPI 專案,等等。 -當你安裝 FastAPI(例如使用 `pip install "fastapi[standard]"`),它會包含一個叫做 `fastapi-cli` 的套件,這個套件提供了 `fastapi` 命令。 +當你安裝 FastAPI(例如使用 `pip install "fastapi[standard]"`)時,會附帶一個可以在終端機執行的命令列程式。 -要運行你的 FastAPI 應用程式來進行開發,你可以使用 `fastapi dev` 命令: +要在開發時運行你的 FastAPI 應用程式,你可以使用 `fastapi dev` 指令:
```console -$ fastapi dev main.py +$ fastapi dev FastAPI Starting development server 🚀 @@ -46,13 +46,66 @@ $ fastapi dev Uvicorn,這是一個高效能、適合生產環境的 ASGI 伺服器。 😎 +此外,其他工具可能找不到它,例如 [VS Code 擴充套件](editor-support.md) 或 [FastAPI Cloud](https://fastapicloud.com),因此建議在 `pyproject.toml` 中使用 `entrypoint`。 ## `fastapi dev` { #fastapi-dev } @@ -70,6 +123,6 @@ FastAPI CLI 接收你的 Python 程式路徑(例如 `main.py`),並自動 /// tip -你可以在[部署文件](deployment/index.md){.internal-link target=_blank}中了解更多相關資訊。 +你可以在[部署文件](deployment/index.md)中了解更多相關資訊。 /// diff --git a/docs/zh-hant/docs/features.md b/docs/zh-hant/docs/features.md index 77c0203073..63194e2556 100644 --- a/docs/zh-hant/docs/features.md +++ b/docs/zh-hant/docs/features.md @@ -6,8 +6,8 @@ ### 建立在開放標準的基礎上 { #based-on-open-standards } -* 使用 OpenAPI 來建立 API,包含 路徑操作、參數、請求內文、安全性等宣告。 -* 使用 JSON Schema(因為 OpenAPI 本身就是基於 JSON Schema)自動生成資料模型文件。 +* 使用 [**OpenAPI**](https://github.com/OAI/OpenAPI-Specification) 來建立 API,包含 路徑操作、參數、請求內文、安全性等宣告。 +* 使用 [**JSON Schema**](https://json-schema.org/)(因為 OpenAPI 本身就是基於 JSON Schema)自動生成資料模型文件。 * 經過縝密的研究後圍繞這些標準進行設計,而不是事後在已有系統上附加的一層功能。 * 這也讓我們在多種語言中可以使用自動**用戶端程式碼生成**。 @@ -15,11 +15,11 @@ FastAPI 能生成互動式 API 文件和探索性的 Web 使用者介面。由於該框架基於 OpenAPI,因此有多種選擇,預設提供了兩種。 -* Swagger UI 提供互動式探索,讓你可以直接從瀏覽器呼叫並測試你的 API 。 +* [**Swagger UI**](https://github.com/swagger-api/swagger-ui) 提供互動式探索,讓你可以直接從瀏覽器呼叫並測試你的 API 。 ![Swagger UI interaction](https://fastapi.tiangolo.com/img/index/index-03-swagger-02.png) -* 使用 ReDoc 的替代 API 文件。 +* 使用 [**ReDoc**](https://github.com/Rebilly/ReDoc) 的替代 API 文件。 ![ReDoc](https://fastapi.tiangolo.com/img/index/index-06-redoc-02.png) @@ -27,7 +27,7 @@ FastAPI 能生成互動式 API 文件和探索性的 Web 使用者介面。由 這一切都基於標準的 **Python 型別**宣告(感謝 Pydantic)。無需學習新的語法,只需使用標準的現代 Python。 -如果你需要 2 分鐘來學習如何使用 Python 型別(即使你不使用 FastAPI),可以看看這個簡短的教學:[Python 型別](python-types.md){.internal-link target=_blank}。 +如果你需要 2 分鐘來學習如何使用 Python 型別(即使你不使用 FastAPI),可以看看這個簡短的教學:[Python 型別](python-types.md)。 如果你寫帶有 Python 型別的程式碼: @@ -75,7 +75,7 @@ my_second_user: User = User(**second_user_data) 整個框架的設計是為了讓使用變得簡單且直觀,在開始開發之前,所有決策都在多個編輯器上進行了測試,以確保提供最佳的開發體驗。 -在最近的 Python 開發者調查中,我們能看到 被使用最多的功能是 autocompletion。 +在最近的 Python 開發者調查中,我們能看到[被使用最多的功能是 autocompletion](https://www.jetbrains.com/research/python-developers-survey-2017/#tools-and-features)。 整個 **FastAPI** 框架就是基於這一點,任何地方都可以進行自動補齊。 @@ -83,11 +83,11 @@ my_second_user: User = User(**second_user_data) 在這裡,你的編輯器可能會這樣幫助你: -* 在 Visual Studio Code 中: +* 在 [Visual Studio Code](https://code.visualstudio.com/) 中: ![editor support](https://fastapi.tiangolo.com/img/vscode-completion.png) -* 在 PyCharm 中: +* 在 [PyCharm](https://www.jetbrains.com/pycharm/) 中: ![editor support](https://fastapi.tiangolo.com/img/pycharm-completion.png) @@ -124,13 +124,13 @@ FastAPI 已經整合了安全性和身份驗證的功能,但不會強制與特 OpenAPI 中定義的安全模式,包括: * HTTP 基本認證。 -* **OAuth2**(也使用 **JWT tokens**)。在 [OAuth2 with JWT](tutorial/security/oauth2-jwt.md){.internal-link target=_blank} 查看教學。 +* **OAuth2**(也使用 **JWT tokens**)。在 [OAuth2 with JWT](tutorial/security/oauth2-jwt.md) 查看教學。 * API 密鑰,在: * 標頭(Header) * 查詢參數 * Cookies,等等。 -加上来自 Starlette(包括 **session cookie**)的所有安全特性。 +加上來自 Starlette(包括 **session cookie**)的所有安全特性。 所有的這些都是可重複使用的工具和套件,可以輕鬆與你的系統、資料儲存(Data Stores)、關聯式資料庫(RDBMS)以及非關聯式資料庫(NoSQL)等等整合。 @@ -159,11 +159,11 @@ FastAPI 有一個使用簡單,但是非常強大的 Pydantic。所以,你有其他 Pydantic 程式碼也能正常工作。 +**FastAPI** 完全相容且基於 [**Pydantic**](https://docs.pydantic.dev/)。所以,你有其他 Pydantic 程式碼也能正常工作。 相容包括基於 Pydantic 的外部函式庫,例如用於資料庫的 ORMs、ODMs。 diff --git a/docs/zh-hant/docs/help-fastapi.md b/docs/zh-hant/docs/help-fastapi.md index 911c566792..343e0dba3e 100644 --- a/docs/zh-hant/docs/help-fastapi.md +++ b/docs/zh-hant/docs/help-fastapi.md @@ -12,7 +12,7 @@ ## 訂閱電子報 { #subscribe-to-the-newsletter } -你可以訂閱(不常發送的)[**FastAPI 與夥伴**電子報](newsletter.md){.internal-link target=_blank},隨時掌握: +你可以訂閱(不常發送的)[**FastAPI 與夥伴**電子報](newsletter.md),隨時掌握: * 關於 FastAPI 與夥伴的最新消息 🚀 * 教學指南 📝 @@ -22,17 +22,17 @@ ## 在 X(Twitter)關注 FastAPI { #follow-fastapi-on-x-twitter } -在 **X(Twitter)** 關注 @fastapi,獲取 **FastAPI** 的最新消息。🐦 +[在 **X(Twitter)** 關注 @fastapi](https://x.com/fastapi),獲取 **FastAPI** 的最新消息。🐦 ## 在 GitHub 為 **FastAPI** 加星 { #star-fastapi-in-github } -你可以在 GitHub 為 FastAPI「加星」(點擊右上角的 star 星號按鈕):https://github.com/fastapi/fastapi。⭐️ +你可以在 GitHub 為 FastAPI「加星」(點擊右上角的 star 星號按鈕):[https://github.com/fastapi/fastapi](https://github.com/fastapi/fastapi)。⭐️ 加上星標後,其他使用者會更容易發現它,並看到它已經對許多人很有幫助。 ## 追蹤 GitHub 儲存庫的發行版 { #watch-the-github-repository-for-releases } -你可以在 GitHub「watch」FastAPI(點擊右上角的「watch」按鈕):https://github.com/fastapi/fastapi。👀 +你可以在 GitHub「watch」FastAPI(點擊右上角的「watch」按鈕):[https://github.com/fastapi/fastapi](https://github.com/fastapi/fastapi)。👀 在那裡你可以選擇「Releases only」。 @@ -40,45 +40,45 @@ ## 與作者連結 { #connect-with-the-author } -你可以與作者 我(Sebastián Ramírez / `tiangolo`) 建立連結。 +你可以與作者 [我(Sebastián Ramírez / `tiangolo`)](https://tiangolo.com) 建立連結。 你可以: -* 在 **GitHub** 關注我。 +* [在 **GitHub** 關注我](https://github.com/tiangolo)。 * 看看我建立的其他開源專案,可能對你有幫助。 * 關注我以便知道我何時建立新的開源專案。 -* 在 **X(Twitter)**Mastodon 關注我。 +* [在 **X(Twitter)**](https://x.com/tiangolo) 或 [Mastodon](https://fosstodon.org/@tiangolo) 關注我。 * 告訴我你如何使用 FastAPI(我很愛聽這些)。 * 接收我發布公告或釋出新工具時的消息。 - * 你也可以在 X(Twitter)關注 @fastapi(另外的帳號)。 -* 在 **LinkedIn** 關注我。 + * 你也可以[在 X(Twitter)關注 @fastapi](https://x.com/fastapi)(另外的帳號)。 +* [在 **LinkedIn** 關注我](https://www.linkedin.com/in/tiangolo/)。 * 接收我發布公告或釋出新工具時的消息(不過我更常用 X(Twitter)🤷‍♂)。 -* 在 **Dev.to****Medium** 閱讀我寫的內容(或關注我)。 +* 在 [**Dev.to**](https://dev.to/tiangolo) 或 [**Medium**](https://medium.com/@tiangolo) 閱讀我寫的內容(或關注我)。 * 閱讀我的想法、文章,以及我建立的工具。 * 關注我以便在我發佈新內容時能第一時間看到。 ## 在 X(Twitter)發文談談 **FastAPI** { #tweet-about-fastapi } -發一則關於 **FastAPI** 的推文,讓我與其他人知道你為什麼喜歡它。🎉 +[發一則關於 **FastAPI** 的推文](https://x.com/compose/tweet?text=I'm loving @fastapi because... https://github.com/fastapi/fastapi),讓我與其他人知道你為什麼喜歡它。🎉 我很樂於聽到 **FastAPI** 是如何被使用、你喜歡它的哪些地方、在哪個專案/公司使用它等等。 ## 為 FastAPI 投票 { #vote-for-fastapi } -* 在 Slant 為 **FastAPI** 投票。 -* 在 AlternativeTo 為 **FastAPI** 投票。 -* 在 StackShare 表示你使用 **FastAPI**。 +* [在 Slant 為 **FastAPI** 投票](https://www.slant.co/options/34241/~fastapi-review)。 +* [在 AlternativeTo 為 **FastAPI** 投票](https://alternativeto.net/software/fastapi/about/)。 +* [在 StackShare 表示你使用 **FastAPI**](https://stackshare.io/pypi-fastapi)。 ## 在 GitHub 幫助他人解答問題 { #help-others-with-questions-in-github } 你可以嘗試幫助他人回答以下地方的問題: -* GitHub Discussions -* GitHub Issues +* [GitHub Discussions](https://github.com/fastapi/fastapi/discussions/categories/questions?discussions_q=category%3AQuestions+is%3Aunanswered) +* [GitHub Issues](https://github.com/fastapi/fastapi/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Aquestion+-label%3Aanswered+) 很多時候你可能已經知道這些問題的解答。🤓 -如果你經常幫大家解決問題,你會成為官方的 [FastAPI 專家](fastapi-people.md#fastapi-experts){.internal-link target=_blank}。🎉 +如果你經常幫大家解決問題,你會成為官方的 [FastAPI 專家](fastapi-people.md#fastapi-experts)。🎉 請記得,最重要的是:盡量友善。大家可能帶著挫折而來,很多時候提問方式不夠理想,但請盡你所能保持友善。🤗 @@ -104,7 +104,7 @@ 很多時候他們只會貼出一小段程式碼,但那不足以**重現問題**。 -* 你可以請他們提供一個最小可重現範例,讓你可以**複製貼上**並在本機執行,看到與他們相同的錯誤或行為,或更好地理解他們的使用情境。 +* 你可以請他們提供一個[最小可重現範例](https://stackoverflow.com/help/minimal-reproducible-example),讓你可以**複製貼上**並在本機執行,看到與他們相同的錯誤或行為,或更好地理解他們的使用情境。 * 如果你有心力,你也可以嘗試自己**建立一個範例**,僅依據問題描述來還原。不過請記得這可能很耗時,或許更好的是先請他們把問題說清楚。 @@ -124,7 +124,7 @@ ## 追蹤 GitHub 儲存庫 { #watch-the-github-repository } -你可以在 GitHub「watch」FastAPI(點擊右上角的「watch」按鈕):https://github.com/fastapi/fastapi。👀 +你可以在 GitHub「watch」FastAPI(點擊右上角的「watch」按鈕):[https://github.com/fastapi/fastapi](https://github.com/fastapi/fastapi)。👀 如果你選擇「Watching」而不是「Releases only」,當有人建立新的 issue 或問題時你會收到通知。你也可以指定只想被通知新的 issues、discussions、PR 等等。 @@ -132,7 +132,7 @@ ## 提問 { #ask-questions } -你可以在 GitHub 儲存庫建立一個新的問題(Question),例如用來: +你可以在 GitHub 儲存庫[建立一個新的問題(Question)](https://github.com/fastapi/fastapi/discussions/new?category=questions),例如用來: * 提出**問題**或詢問某個**疑難**。 * 建議一個新的**功能**。 @@ -195,12 +195,12 @@ ## 建立 Pull Request { #create-a-pull-request } -你可以透過 Pull Request 來[貢獻](contributing.md){.internal-link target=_blank}原始碼,例如: +你可以透過 Pull Request 來[貢獻](contributing.md)原始碼,例如: * 修正文檔中你發現的錯字。 -* 分享你建立或發現的 FastAPI 相關文章、影片或 podcast,方法是編輯這個檔案。 +* 分享你建立或發現的 FastAPI 相關文章、影片或 podcast,方法是[編輯這個檔案](https://github.com/fastapi/fastapi/edit/master/docs/en/data/external_links.yml)。 * 請確保把你的連結加到對應章節的開頭。 -* 協助把[文件翻譯](contributing.md#translations){.internal-link target=_blank}成你的語言。 +* 協助把[文件翻譯](contributing.md#translations)成你的語言。 * 你也可以幫忙審查他人提交的翻譯。 * 提議新的文件章節。 * 修復既有的 issue/bug。 @@ -217,8 +217,8 @@ 你現在就能做的主要任務有: -* [在 GitHub 幫助他人解答問題](#help-others-with-questions-in-github){.internal-link target=_blank}(見上方章節)。 -* [審核 Pull Request](#review-pull-requests){.internal-link target=_blank}(見上方章節)。 +* [在 GitHub 幫助他人解答問題](#help-others-with-questions-in-github)(見上方章節)。 +* [審核 Pull Request](#review-pull-requests)(見上方章節)。 這兩件事是**最耗時**的。這也是維護 FastAPI 的主要工作。 @@ -226,11 +226,11 @@ ## 加入聊天室 { #join-the-chat } -加入 👥 Discord 聊天伺服器 👥,與 FastAPI 社群的其他人一起交流。 +加入 👥 [Discord 聊天伺服器](https://discord.gg/VQjSZaeJmf) 👥,與 FastAPI 社群的其他人一起交流。 /// tip -若要提問,請到 GitHub Discussions,在那裡更有機會獲得[FastAPI 專家](fastapi-people.md#fastapi-experts){.internal-link target=_blank}的協助。 +若要提問,請到 [GitHub Discussions](https://github.com/fastapi/fastapi/discussions/new?category=questions),在那裡更有機會獲得[FastAPI 專家](fastapi-people.md#fastapi-experts)的協助。 聊天室請僅用於其他一般性的交流。 @@ -242,13 +242,13 @@ 在 GitHub 上,模板會引導你寫出合適的提問,讓你更容易得到好的解答,甚至在提問前就自己解決問題。而且在 GitHub 上,我能確保最終都會回覆(即使需要一些時間)。我個人無法在聊天系統做到這一點。😅 -聊天系統中的對話也不像 GitHub 那樣容易被搜尋,因此問題與答案可能在對話中淹沒。而且只有 GitHub 上的問題與回答才會被計入成為[FastAPI 專家](fastapi-people.md#fastapi-experts){.internal-link target=_blank},因此你在 GitHub 上更有機會獲得關注。 +聊天系統中的對話也不像 GitHub 那樣容易被搜尋,因此問題與答案可能在對話中淹沒。而且只有 GitHub 上的問題與回答才會被計入成為[FastAPI 專家](fastapi-people.md#fastapi-experts),因此你在 GitHub 上更有機會獲得關注。 另一方面,聊天室裡有成千上萬的使用者,所以幾乎隨時都有很大的機會能找到人聊天。😄 ## 贊助作者 { #sponsor-the-author } -如果你的**產品/公司**依賴或與 **FastAPI** 相關,且你想觸及它的使用者,你可以透過 GitHub sponsors 贊助作者(我)。依據不同級別,你可能會得到一些額外福利,例如在文件中顯示徽章。🎁 +如果你的**產品/公司**依賴或與 **FastAPI** 相關,且你想觸及它的使用者,你可以透過 [GitHub sponsors](https://github.com/sponsors/tiangolo) 贊助作者(我)。依據不同級別,你可能會得到一些額外福利,例如在文件中顯示徽章。🎁 --- diff --git a/docs/zh-hant/docs/history-design-future.md b/docs/zh-hant/docs/history-design-future.md index b7f57a3636..f3c733330a 100644 --- a/docs/zh-hant/docs/history-design-future.md +++ b/docs/zh-hant/docs/history-design-future.md @@ -1,6 +1,6 @@ # 歷史、設計與未來 { #history-design-and-future } -不久之前,一位 **FastAPI** 使用者提問: +不久之前,[一位 **FastAPI** 使用者提問](https://github.com/fastapi/fastapi/issues/3#issuecomment-454956920): > 這個專案的歷史是什麼?看起來它在短短幾週內從默默無名變得非常厲害 [...] @@ -14,7 +14,7 @@ **FastAPI** 的歷史,在很大程度上也是其前身工具的歷史。 -如在[替代方案](alternatives.md){.internal-link target=_blank}章節所述: +如在[替代方案](alternatives.md)一節所述:
@@ -44,9 +44,9 @@ 我在最受歡迎的 Python 編輯器中測試了多個想法:PyCharm、VS Code、基於 Jedi 的編輯器。 -根據最新的 Python 開發者調查,這些工具涵蓋約 80% 的使用者。 +根據最新的 [Python 開發者調查](https://www.jetbrains.com/research/python-developers-survey-2018/#development-tools),這些工具涵蓋約 80% 的使用者。 -這表示 **FastAPI** 已針對 80% 的 Python 開發者所使用的編輯器進行過專門測試。而由於其他多數編輯器的行為也類似,這些優點幾乎在所有編輯器上都能生效。 +這表示 **FastAPI** 已針對 80% 的 Python 開發者所使用的編輯器進行過專門測試。而由於其他多數編輯器的行為也類似,這些優點擴及實際上幾乎所有編輯器。 藉此我找到了盡可能減少程式碼重複、在各處提供自動補全、型別與錯誤檢查等的最佳方式。 @@ -54,11 +54,11 @@ ## 需求 { #requirements } -在測試多種替代方案後,我決定採用 **Pydantic**,因為它的優勢。 +在測試多種替代方案後,我決定採用 [**Pydantic**](https://docs.pydantic.dev/),因為它的優勢。 隨後我也對它做出貢獻,使其完全符合 JSON Schema、支援以不同方式定義約束,並依據在多款編輯器中的測試結果改進編輯器支援(型別檢查、自動補全)。 -在開發過程中,我也對 **Starlette**(另一個關鍵依賴)做出貢獻。 +在開發過程中,我也對 [**Starlette**](https://www.starlette.dev/)(另一個關鍵依賴)做出貢獻。 ## 開發 { #development } @@ -76,4 +76,4 @@ **FastAPI** 的前景非常光明。 -也非常感謝[你的幫助](help-fastapi.md){.internal-link target=_blank}。 +也非常感謝[你的幫助](help-fastapi.md)。 diff --git a/docs/zh-hant/docs/index.md b/docs/zh-hant/docs/index.md index 77eba9b149..d57791bf8b 100644 --- a/docs/zh-hant/docs/index.md +++ b/docs/zh-hant/docs/index.md @@ -11,25 +11,25 @@ FastAPI 框架,高效能,易於學習,快速開發,適用於生產環境

- + Test - + Coverage - + Package version - + Supported Python versions

--- -**文件**: https://fastapi.tiangolo.com/zh-hant +**文件**: [https://fastapi.tiangolo.com/zh-hant](https://fastapi.tiangolo.com/zh-hant) -**程式碼**: https://github.com/fastapi/fastapi +**程式碼**: [https://github.com/fastapi/fastapi](https://github.com/fastapi/fastapi) --- @@ -44,7 +44,7 @@ FastAPI 是一個現代、快速(高效能)的 Web 框架,用於以 Python * **簡單**:設計上易於使用與學習。更少的讀文件時間。 * **簡潔**:最小化程式碼重複性。每個參數宣告可帶來多個功能。更少的錯誤。 * **穩健**:立即獲得可投入生產的程式碼,並自動生成互動式文件。 -* **標準化**:基於(且完全相容於)API 的開放標準:OpenAPI(之前稱為 Swagger)和 JSON Schema。 +* **標準化**:基於(且完全相容於)API 的開放標準:[OpenAPI](https://github.com/OAI/OpenAPI-Specification)(之前稱為 Swagger)和 [JSON Schema](https://json-schema.org/)。 * 基於內部開發團隊在建立生產應用程式時的測試預估。 @@ -55,51 +55,51 @@ FastAPI 是一個現代、快速(高效能)的 Web 框架,用於以 Python ### 基石贊助商 { #keystone-sponsor } {% for sponsor in sponsors.keystone -%} - + {% endfor -%} ### 金級與銀級贊助商 { #gold-and-silver-sponsors } {% for sponsor in sponsors.gold -%} - + {% endfor -%} {%- for sponsor in sponsors.silver -%} - + {% endfor %} -其他贊助商 +[其他贊助商](https://fastapi.tiangolo.com/zh-hant/fastapi-people/#sponsors) ## 評價 { #opinions } "_[...] 近期大量使用 **FastAPI**。[...] 我實際上打算在我在**微軟**團隊的所有**機器學習**服務上使用它。其中一些正在整合到核心的 **Windows** 產品,以及一些 **Office** 產品。_" -
Kabir Khan - Microsoft (ref)
+
Kabir Khan - Microsoft (ref)
--- "_我們採用了 **FastAPI** 函式庫來啟動一個 **REST** 伺服器,供查詢以取得**預測**。[for Ludwig]_" -
Piero Molino, Yaroslav Dudin, and Sai Sumanth Miryala - Uber (ref)
+
Piero Molino, Yaroslav Dudin, and Sai Sumanth Miryala - Uber (ref)
--- "_**Netflix** 很高興宣布我們的**危機管理**協調框架 **Dispatch** 開源![使用 **FastAPI** 建構]_" -
Kevin Glisson, Marc Vilanova, Forest Monsen - Netflix (ref)
+
Kevin Glisson, Marc Vilanova, Forest Monsen - Netflix (ref)
--- "_我對 **FastAPI** 興奮得不得了。超好玩!_" -
Brian Okken - Python Bytes podcast 主持人 (ref)
+
Brian Okken - [Python Bytes](https://pythonbytes.fm/episodes/show/123/time-to-right-the-py-wrongs?time_in_sec=855) podcast 主持人 (ref)
--- "_老實說,你們做的看起來非常穩健又精緻。很多方面都正是我希望 **Hug** 成為的樣子——看到有人把它建出來真的很鼓舞人心。_" -
Timothy Crosley - Hug 創作者 (ref)
+
Timothy Crosley - [Hug](https://github.com/hugapi/hug) 創作者 (ref)
--- @@ -107,27 +107,27 @@ FastAPI 是一個現代、快速(高效能)的 Web 框架,用於以 Python "_我們的 **API** 已經改用 **FastAPI** [...] 我想你會喜歡它 [...]_" -
Ines Montani - Matthew Honnibal - Explosion AI 創辦人 - spaCy 創作者 (ref) - (ref)
+
Ines Montani - Matthew Honnibal - [Explosion AI](https://explosion.ai) 創辦人 - [spaCy](https://spacy.io) 創作者 (ref) - (ref)
--- -"_如果有人想要建立一個可投入生產的 Python API,我強烈推薦 **FastAPI**。它**設計精美**、**使用簡單**且**高度可擴充**,已成為我們 API 優先開發策略中的**關鍵組件**,推動了許多自動化與服務,例如我們的 Virtual TAC Engineer。_" +"_如果有人想要打造一個可用於生產環境的 Python API,我強力推薦 **FastAPI**。它**設計優雅**、**簡單易用**且**高度可擴展**,已經成為我們 API first 開發策略中的**關鍵元件**,推動了許多自動化與服務,例如我們的 Virtual TAC Engineer。_" -
Deon Pillsbury - Cisco (ref)
+
Deon Pillsbury - Cisco (ref)
--- ## FastAPI 迷你紀錄片 { #fastapi-mini-documentary } -在 2025 年底發布了一支 FastAPI 迷你紀錄片,你可以在線上觀看: +在 2025 年底發布了一支 [FastAPI 迷你紀錄片](https://www.youtube.com/watch?v=mpR8ngthqiE),你可以在線上觀看: -FastAPI Mini Documentary +FastAPI Mini Documentary ## **Typer**,命令列的 FastAPI { #typer-the-fastapi-of-clis } - + -如果你不是在做 Web API,而是要建立一個在終端機中使用的 CLI 應用程式,可以看看 **Typer**。 +如果你不是在做 Web API,而是要建立一個在終端機中使用的 CLI 應用程式,可以看看 [**Typer**](https://typer.tiangolo.com/)。 **Typer** 是 FastAPI 的小老弟。他立志成為命令列世界的 **FastAPI**。⌨️ 🚀 @@ -135,12 +135,12 @@ FastAPI 是一個現代、快速(高效能)的 Web 框架,用於以 Python FastAPI 是站在以下巨人的肩膀上: -* Starlette 負責 Web 部分。 -* Pydantic 負責資料部分。 +* [Starlette](https://www.starlette.dev/) 負責 Web 部分。 +* [Pydantic](https://docs.pydantic.dev/) 負責資料部分。 ## 安裝 { #installation } -建立並啟用一個虛擬環境,然後安裝 FastAPI: +建立並啟用一個[虛擬環境](https://fastapi.tiangolo.com/zh-hant/virtual-environments/),然後安裝 FastAPI:
@@ -199,7 +199,7 @@ async def read_item(item_id: int, q: str | None = None): **注意**: -如果你不確定,請查看文件中 _"In a hurry?"_ 章節的 `async` 與 `await`。 +如果你不確定,請查看文件中 _"In a hurry?"_ 章節的[關於文件中的 `async` 與 `await`](https://fastapi.tiangolo.com/zh-hant/async/#in-a-hurry)。 @@ -210,7 +210,7 @@ async def read_item(item_id: int, q: str | None = None):
```console -$ fastapi dev main.py +$ fastapi dev ╭────────── FastAPI CLI - Development mode ───────────╮ │ │ @@ -235,19 +235,19 @@ INFO: Application startup complete.
-關於指令 fastapi dev main.py... +關於指令 fastapi dev... -指令 `fastapi dev` 會讀取你的 `main.py`,偵測其中的 **FastAPI** 應用,並使用 Uvicorn 啟動伺服器。 +指令 `fastapi dev` 會讀取你的 `main.py`,偵測其中的 **FastAPI** 應用,並使用 [Uvicorn](https://www.uvicorn.dev) 啟動伺服器。 預設情況下,`fastapi dev` 會在本機開發時啟用自動重新載入。 -可在 FastAPI CLI 文件中閱讀更多資訊。 +可在 [FastAPI CLI 文件](https://fastapi.tiangolo.com/zh-hant/fastapi-cli/)中閱讀更多資訊。
### 檢查 { #check-it } -使用瀏覽器開啟 http://127.0.0.1:8000/items/5?q=somequery。 +使用瀏覽器開啟 [http://127.0.0.1:8000/items/5?q=somequery](http://127.0.0.1:8000/items/5?q=somequery)。 你將會看到以下 JSON 回應: @@ -264,17 +264,17 @@ INFO: Application startup complete. ### 互動式 API 文件 { #interactive-api-docs } -接著前往 http://127.0.0.1:8000/docs。 +接著前往 [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs)。 -你會看到自動生成的互動式 API 文件(由 Swagger UI 提供): +你會看到自動生成的互動式 API 文件(由 [Swagger UI](https://github.com/swagger-api/swagger-ui) 提供): ![Swagger UI](https://fastapi.tiangolo.com/img/index/index-01-swagger-ui-simple.png) ### 替代 API 文件 { #alternative-api-docs } -現在前往 http://127.0.0.1:8000/redoc。 +現在前往 [http://127.0.0.1:8000/redoc](http://127.0.0.1:8000/redoc)。 -你會看到另一種自動文件(由 ReDoc 提供): +你會看到另一種自動文件(由 [ReDoc](https://github.com/Rebilly/ReDoc) 提供): ![ReDoc](https://fastapi.tiangolo.com/img/index/index-02-redoc-simple.png) @@ -316,7 +316,7 @@ def update_item(item_id: int, item: Item): ### 互動式 API 文件升級 { #interactive-api-docs-upgrade } -前往 http://127.0.0.1:8000/docs。 +前往 [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs)。 * 互動式 API 文件會自動更新,包含新的 body: @@ -332,7 +332,7 @@ def update_item(item_id: int, item: Item): ### 替代 API 文件升級 { #alternative-api-docs-upgrade } -現在前往 http://127.0.0.1:8000/redoc。 +現在前往 [http://127.0.0.1:8000/redoc](http://127.0.0.1:8000/redoc)。 * 替代文件也會反映新的查詢參數與 body: @@ -433,7 +433,7 @@ item: Item ![editor support](https://fastapi.tiangolo.com/img/vscode-completion.png) -若想看包含更多功能的完整範例,請參考 教學 - 使用者指南。 +若想看包含更多功能的完整範例,請參考 Tutorial - User Guide。 **劇透警告**:教學 - 使用者指南包含: @@ -442,7 +442,7 @@ item: Item * 一個非常強大且易用的 **依賴注入** 系統。 * 安全與驗證,包含支援 **OAuth2** 搭配 **JWT tokens** 與 **HTTP Basic** 驗證。 * 宣告**深度巢狀 JSON 模型**的進階(但同樣簡單)技巧(感謝 Pydantic)。 -* 與 Strawberry 及其他函式庫的 **GraphQL** 整合。 +* 與 [Strawberry](https://strawberry.rocks) 及其他函式庫的 **GraphQL** 整合。 * 許多額外功能(感謝 Starlette),例如: * **WebSockets** * 基於 HTTPX 與 `pytest` 的極其簡單的測試 @@ -452,24 +452,10 @@ item: Item ### 部署你的應用(可選) { #deploy-your-app-optional } -你也可以選擇將 FastAPI 應用部署到 FastAPI Cloud,如果你還沒加入,去登記等候名單吧。🚀 +你也可以選擇將 FastAPI 應用部署到 [FastAPI Cloud](https://fastapicloud.com),如果你還沒加入,去登記等候名單吧。🚀 如果你已經有 **FastAPI Cloud** 帳號(我們已從等候名單邀請你 😉),你可以用一個指令部署你的應用。 -部署前,先確認你已登入: - -
- -```console -$ fastapi login - -You are logged in to FastAPI Cloud 🚀 -``` - -
- -接著部署你的應用: -
```console @@ -488,7 +474,7 @@ Deploying to FastAPI Cloud... #### 關於 FastAPI Cloud { #about-fastapi-cloud } -**FastAPI Cloud** 由 **FastAPI** 的同一位作者與團隊打造。 +**[FastAPI Cloud](https://fastapicloud.com)** 由 **FastAPI** 的同一位作者與團隊打造。 它讓你以最小的努力精簡地完成 API 的**建置**、**部署**與**存取**流程。 @@ -504,9 +490,9 @@ FastAPI 是開源且基於標準。你可以把 FastAPI 應用部署到任何你 ## 效能 { #performance } -獨立的 TechEmpower 基準測試顯示,在 Uvicorn 下運行的 **FastAPI** 應用是最快的 Python 框架之一,僅次於 Starlette 與 Uvicorn 本身(FastAPI 內部使用它們)。(*) +獨立的 TechEmpower 基準測試顯示,在 Uvicorn 下運行的 **FastAPI** 應用是[最快的 Python 框架之一](https://www.techempower.com/benchmarks/#section=test&runid=7464e520-0dc2-473d-bd34-dbdfd7e85911&hw=ph&test=query&l=zijzen-7),僅次於 Starlette 與 Uvicorn 本身(FastAPI 內部使用它們)。(*) -想了解更多,請參閱測試結果。 +想了解更多,請參閱[測試結果](https://fastapi.tiangolo.com/zh-hant/benchmarks/)。 ## 依賴套件 { #dependencies } @@ -518,19 +504,19 @@ FastAPI 依賴 Pydantic 與 Starlette。 Pydantic 會使用: -* email-validator - 用於電子郵件驗證。 +* [`email-validator`](https://github.com/JoshData/python-email-validator) - 用於電子郵件驗證。 Starlette 會使用: -* httpx - 若要使用 `TestClient` 必須安裝。 -* jinja2 - 若要使用預設的模板設定必須安裝。 -* python-multipart - 若要支援表單 "解析",搭配 `request.form()`。 +* [`httpx`](https://www.python-httpx.org) - 若要使用 `TestClient` 必須安裝。 +* [`jinja2`](https://jinja.palletsprojects.com) - 若要使用預設的模板設定必須安裝。 +* [`python-multipart`](https://github.com/Kludex/python-multipart) - 若要支援表單 "解析",搭配 `request.form()`。 FastAPI 會使用: -* uvicorn - 用於載入並服務你的應用的伺服器。這包含 `uvicorn[standard]`,其中含有一些高效能服務所需的依賴(例如 `uvloop`)。 +* [`uvicorn`](https://www.uvicorn.dev) - 用於載入並服務你的應用的伺服器。這包含 `uvicorn[standard]`,其中含有一些高效能服務所需的依賴(例如 `uvloop`)。 * `fastapi-cli[standard]` - 提供 `fastapi` 指令。 - * 其中包含 `fastapi-cloud-cli`,可讓你將 FastAPI 應用部署到 FastAPI Cloud。 + * 其中包含 `fastapi-cloud-cli`,可讓你將 FastAPI 應用部署到 [FastAPI Cloud](https://fastapicloud.com)。 ### 不含 `standard` 依賴套件 { #without-standard-dependencies } @@ -546,13 +532,13 @@ FastAPI 會使用: Pydantic 的額外可選依賴: -* pydantic-settings - 設定管理。 -* pydantic-extra-types - 與 Pydantic 一起使用的額外型別。 +* [`pydantic-settings`](https://docs.pydantic.dev/latest/usage/pydantic_settings/) - 設定管理。 +* [`pydantic-extra-types`](https://docs.pydantic.dev/latest/usage/types/extra_types/extra_types/) - 與 Pydantic 一起使用的額外型別。 FastAPI 的額外可選依賴: -* orjson - 若要使用 `ORJSONResponse` 必須安裝。 -* ujson - 若要使用 `UJSONResponse` 必須安裝。 +* [`orjson`](https://github.com/ijl/orjson) - 若要使用 `ORJSONResponse` 必須安裝。 +* [`ujson`](https://github.com/esnme/ultrajson) - 若要使用 `UJSONResponse` 必須安裝。 ## 授權 { #license } diff --git a/docs/zh-hant/docs/project-generation.md b/docs/zh-hant/docs/project-generation.md index 7fa92ce558..fc5c8e4655 100644 --- a/docs/zh-hant/docs/project-generation.md +++ b/docs/zh-hant/docs/project-generation.md @@ -4,7 +4,7 @@ 你可以使用此範本快速起步,裡面已替你完成大量初始設定、安全性、資料庫,以及部分 API 端點。 -GitHub 儲存庫:全端 FastAPI 範本 +GitHub 儲存庫:[全端 FastAPI 範本](https://github.com/tiangolo/full-stack-fastapi-template) ## 全端 FastAPI 範本 - 技術堆疊與功能 { #full-stack-fastapi-template-technology-stack-and-features } diff --git a/docs/zh-hant/docs/python-types.md b/docs/zh-hant/docs/python-types.md index 4f498ab734..4193069ea7 100644 --- a/docs/zh-hant/docs/python-types.md +++ b/docs/zh-hant/docs/python-types.md @@ -269,7 +269,7 @@ def some_function(data: Any): ## Pydantic 模型 { #pydantic-models } -Pydantic 是一個用來做資料驗證的 Python 程式庫。 +[Pydantic](https://docs.pydantic.dev/) 是一個用來做資料驗證的 Python 程式庫。 你以帶有屬性的類別來宣告資料的「形狀」。 @@ -285,13 +285,13 @@ def some_function(data: Any): /// info | 資訊 -想了解更多 Pydantic,請查看它的文件。 +想了解更多 [Pydantic,請查看它的文件](https://docs.pydantic.dev/)。 /// **FastAPI** 完全是以 Pydantic 為基礎。 -你會在[教學 - 使用者指南](tutorial/index.md){.internal-link target=_blank}中看到更多實際範例。 +你會在[教學 - 使用者指南](tutorial/index.md)中看到更多實際範例。 ## 含中繼資料的型別提示 { #type-hints-with-metadata-annotations } @@ -337,12 +337,12 @@ Python 本身不會對這個 `Annotated` 做任何事。對編輯器與其他工 * 使用 OpenAPI 書寫 API 文件: * 之後會由自動的互動式文件介面所使用 -這些現在聽起來可能有點抽象。別擔心。你會在[教學 - 使用者指南](tutorial/index.md){.internal-link target=_blank}中看到它們的實際運作。 +這些現在聽起來可能有點抽象。別擔心。你會在[教學 - 使用者指南](tutorial/index.md)中看到它們的實際運作。 重點是,透過在單一位置使用標準的 Python 型別(而不是新增更多類別、裝飾器等),**FastAPI** 會幫你完成很多工作。 /// info | 資訊 -如果你已經完整讀完整個教學,並回來想多看一些關於型別的內容,一個不錯的資源是 `mypy` 的「小抄」。 +如果你已經完整讀完整個教學,並回來想多看一些關於型別的內容,一個不錯的資源是 [`mypy` 的「小抄」](https://mypy.readthedocs.io/en/latest/cheat_sheet_py3.html)。 /// diff --git a/docs/zh-hant/docs/tutorial/bigger-applications.md b/docs/zh-hant/docs/tutorial/bigger-applications.md index d8b8c9bff8..a37c16c39e 100644 --- a/docs/zh-hant/docs/tutorial/bigger-applications.md +++ b/docs/zh-hant/docs/tutorial/bigger-applications.md @@ -123,7 +123,7 @@ from app.routers import items 為了簡化範例,我們使用了一個虛構的標頭。 -但在真實情況下,使用內建的[安全工具](security/index.md){.internal-link target=_blank}會有更好的效果。 +但在真實情況下,使用內建的 [安全工具](security/index.md) 會有更好的效果。 /// @@ -169,7 +169,7 @@ async def read_item(item_id: str): /// tip | 提示 -請注意,就像在[路徑操作裝飾器中的相依性](dependencies/dependencies-in-path-operation-decorators.md){.internal-link target=_blank}一樣,不會把任何值傳遞給你的路徑操作函式(path operation function)。 +請注意,就像在[路徑操作裝飾器中的相依性](dependencies/dependencies-in-path-operation-decorators.md)一樣,不會把任何值傳遞給你的路徑操作函式(path operation function)。 /// @@ -185,8 +185,8 @@ async def read_item(item_id: str): * 它們都會包含預先定義的 `responses`。 * 這些路徑操作都會在執行前評估 / 執行其 `dependencies` 清單。 * 如果你也在特定的路徑操作中宣告了相依性,這些相依性也會被執行。 - * Router 的相依性會先執行,然後是[裝飾器中的 `dependencies`](dependencies/dependencies-in-path-operation-decorators.md){.internal-link target=_blank},最後是一般參數相依性。 - * 你也可以加入帶有 `scopes` 的 [`Security` 相依性](../advanced/security/oauth2-scopes.md){.internal-link target=_blank}。 + * Router 的相依性會先執行,然後是[裝飾器中的 `dependencies`](dependencies/dependencies-in-path-operation-decorators.md),最後是一般參數相依性。 + * 你也可以加入帶有 `scopes` 的 [`Security` 相依性](../advanced/security/oauth2-scopes.md)。 /// tip | 提示 @@ -303,7 +303,7 @@ from ...dependencies import get_token_header 照常匯入並建立 `FastAPI` 類別。 -我們甚至可以宣告[全域相依性](dependencies/global-dependencies.md){.internal-link target=_blank},它們會與各 `APIRouter` 的相依性合併: +我們甚至可以宣告[全域相依性](dependencies/global-dependencies.md),它們會與各 `APIRouter` 的相依性合併: {* ../../docs_src/bigger_applications/app_an_py310/main.py hl[1,3,7] title["app/main.py"] *} @@ -353,7 +353,7 @@ from .routers import items, users from app.routers import items, users ``` -想了解更多關於 Python 套件與模組,請閱讀官方的模組說明文件。 +想了解更多關於 Python 套件與模組,請閱讀[官方的模組說明文件](https://docs.python.org/3/tutorial/modules.html)。 /// @@ -465,6 +465,37 @@ from .routers.users import router /// +## 在 `pyproject.toml` 設定 `entrypoint` { #configure-the-entrypoint-in-pyproject-toml } + +因為你的 FastAPI `app` 物件位在 `app/main.py`,你可以在 `pyproject.toml` 檔案中這樣設定 `entrypoint`: + +```toml +[tool.fastapi] +entrypoint = "app.main:app" +``` + +這等同於這樣匯入: + +```python +from app.main import app +``` + +如此一來 `fastapi` 指令就會知道去哪裡找到你的 app。 + +/// Note | 注意 + +你也可以把路徑直接傳給指令,例如: + +```console +$ fastapi dev app/main.py +``` + +但你每次呼叫 `fastapi` 指令時都得記得傳入正確的路徑。 + +此外,其他工具可能找不到它,例如 [VS Code 擴充套件](../editor-support.md) 或 [FastAPI Cloud](https://fastapicloud.com),因此建議在 `pyproject.toml` 中使用 `entrypoint`。 + +/// + ## 檢查自動產生的 API 文件 { #check-the-automatic-api-docs } 現在,執行你的應用: @@ -472,14 +503,14 @@ from .routers.users import router
```console -$ fastapi dev app/main.py +$ fastapi dev INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) ```
-然後開啟位於 http://127.0.0.1:8000/docs 的文件。 +然後開啟位於 [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) 的文件。 你會看到自動產生的 API 文件,包含來自所有子模組的路徑,使用正確的路徑(與前綴)與正確的標籤: diff --git a/docs/zh-hant/docs/tutorial/body-updates.md b/docs/zh-hant/docs/tutorial/body-updates.md index a309e3522c..0d48e28424 100644 --- a/docs/zh-hant/docs/tutorial/body-updates.md +++ b/docs/zh-hant/docs/tutorial/body-updates.md @@ -2,7 +2,7 @@ ## 使用 `PUT` 取代式更新 { #update-replacing-with-put } -要更新一個項目,你可以使用 HTTP `PUT` 操作。 +要更新一個項目,你可以使用 [HTTP `PUT`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT) 操作。 你可以使用 `jsonable_encoder` 將輸入資料轉換為可儲存為 JSON 的資料(例如用於 NoSQL 資料庫)。例如把 `datetime` 轉成 `str`。 @@ -28,7 +28,7 @@ ## 使用 `PATCH` 進行部分更新 { #partial-updates-with-patch } -你也可以使用 HTTP `PATCH` 操作來進行*部分*更新。 +你也可以使用 [HTTP `PATCH`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH) 操作來進行*部分*更新。 這表示你只需傳送想要更新的資料,其餘保持不變。 @@ -95,6 +95,6 @@ 因此,如果你希望接收可以省略所有屬性的部分更新,你需要一個所有屬性皆為可選(具預設值或為 `None`)的模型。 -為了區分用於更新(全部可選)與用於建立(欄位為必填)的模型,你可以參考 [額外模型](extra-models.md){.internal-link target=_blank} 中的做法。 +為了區分用於更新(全部可選)與用於建立(欄位為必填)的模型,你可以參考 [額外模型](extra-models.md) 中的做法。 /// diff --git a/docs/zh-hant/docs/tutorial/cors.md b/docs/zh-hant/docs/tutorial/cors.md index 5fa497c081..4fcf9f9418 100644 --- a/docs/zh-hant/docs/tutorial/cors.md +++ b/docs/zh-hant/docs/tutorial/cors.md @@ -1,6 +1,6 @@ # CORS(跨來源資源共用) { #cors-cross-origin-resource-sharing } -CORS 或「Cross-Origin Resource Sharing」指的是:當在瀏覽器中執行的前端以 JavaScript 與後端通訊,而後端與前端位於不同「來源(origin)」時的情境。 +[CORS 或「Cross-Origin Resource Sharing」](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)指的是:當在瀏覽器中執行的前端以 JavaScript 與後端通訊,而後端與前端位於不同「來源(origin)」時的情境。 ## 來源(Origin) { #origin } @@ -55,10 +55,10 @@ * `allow_origins` - 允許進行跨來源請求的來源清單。例如 `['https://example.org', 'https://www.example.org']`。你可以使用 `['*']` 來允許任何來源。 * `allow_origin_regex` - 允許進行跨來源請求的來源,使用正規表示式字串比對。例如 `'https://.*\.example\.org'`。 * `allow_methods` - 允許跨來源請求的 HTTP 方法清單。預設為 `['GET']`。你可以使用 `['*']` 來允許所有標準方法。 -* `allow_headers` - 允許跨來源請求所支援的 HTTP 請求標頭清單。預設為 `[]`。你可以使用 `['*']` 來允許所有標頭。對於簡單 CORS 請求,`Accept`、`Accept-Language`、`Content-Language` 與 `Content-Type` 標頭一律被允許。 +* `allow_headers` - 允許跨來源請求所支援的 HTTP 請求標頭清單。預設為 `[]`。你可以使用 `['*']` 來允許所有標頭。對於[簡單 CORS 請求](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests),`Accept`、`Accept-Language`、`Content-Language` 與 `Content-Type` 標頭一律被允許。 * `allow_credentials` - 指示是否支援跨來源請求的 Cookie。預設為 `False`。 - 當 `allow_credentials` 設為 `True` 時,`allow_origins`、`allow_methods` 與 `allow_headers` 都不能設為 `['*']`。上述各項必須明確指定。 + 當 `allow_credentials` 設為 `True` 時,`allow_origins`、`allow_methods` 與 `allow_headers` 都不能設為 `['*']`。上述各項必須[明確指定](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#credentialed_requests_and_wildcards)。 * `expose_headers` - 指示哪些回應標頭應該讓瀏覽器可存取。預設為 `[]`。 * `max_age` - 設定瀏覽器快取 CORS 回應的最長秒數。預設為 `600`。 @@ -77,7 +77,7 @@ ## 更多資訊 { #more-info } -想進一步了解 CORS,請參考 Mozilla 的 CORS 文件。 +想進一步了解 CORS,請參考 [Mozilla 的 CORS 文件](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)。 /// note | 技術細節 diff --git a/docs/zh-hant/docs/tutorial/debugging.md b/docs/zh-hant/docs/tutorial/debugging.md index cb82ee417b..1230ed6ccd 100644 --- a/docs/zh-hant/docs/tutorial/debugging.md +++ b/docs/zh-hant/docs/tutorial/debugging.md @@ -59,7 +59,7 @@ $ python myapp.py ```Python from myapp import app -# Some more code +# 其他程式碼 ``` 在那種情況下,`myapp.py` 中自動建立的變數 `__name__` 就不會是 `"__main__"`。 @@ -74,7 +74,7 @@ from myapp import app /// info | 說明 -想了解更多,參考 Python 官方文件。 +想了解更多,參考 [Python 官方文件](https://docs.python.org/3/library/__main__.html)。 /// diff --git a/docs/zh-hant/docs/tutorial/encoder.md b/docs/zh-hant/docs/tutorial/encoder.md index 03b7db6394..9b541adce6 100644 --- a/docs/zh-hant/docs/tutorial/encoder.md +++ b/docs/zh-hant/docs/tutorial/encoder.md @@ -12,7 +12,7 @@ 例如,它不接受 `datetime` 物件,因為那與 JSON 不相容。 -因此,必須將 `datetime` 物件轉為一個以 ISO 格式 表示資料的 `str`。 +因此,必須將 `datetime` 物件轉為一個以 [ISO 格式](https://en.wikipedia.org/wiki/ISO_8601) 表示資料的 `str`。 同樣地,這個資料庫不會接受 Pydantic 模型(帶有屬性的物件),只接受 `dict`。 @@ -24,7 +24,7 @@ 在此範例中,它會把 Pydantic 模型轉成 `dict`,並將 `datetime` 轉成 `str`。 -呼叫後的結果可以用 Python 標準的 `json.dumps()` 進行編碼。 +呼叫後的結果可以用 Python 標準的 [`json.dumps()`](https://docs.python.org/3/library/json.html#json.dumps) 進行編碼。 它不會回傳一個包含 JSON 內容的大型 `str`(字串)。它會回傳 Python 標準的資料結構(例如 `dict`),其中的值與子值都與 JSON 相容。 diff --git a/docs/zh-hant/docs/tutorial/extra-data-types.md b/docs/zh-hant/docs/tutorial/extra-data-types.md index f516d965a4..a5573379d8 100644 --- a/docs/zh-hant/docs/tutorial/extra-data-types.md +++ b/docs/zh-hant/docs/tutorial/extra-data-types.md @@ -36,7 +36,7 @@ * `datetime.timedelta`: * Python 的 `datetime.timedelta`。 * 在請求與回應中會以總秒數的 `float` 表示。 - * Pydantic 也允許用「ISO 8601 time diff encoding」來表示,詳情見文件。 + * Pydantic 也允許用「ISO 8601 time diff encoding」來表示,[詳情見文件](https://docs.pydantic.dev/latest/concepts/serialization/#custom-serializers)。 * `frozenset`: * 在請求與回應中與 `set` 相同處理: * 在請求中,會讀取一個 list,去除重複並轉為 `set`。 @@ -49,7 +49,7 @@ * `Decimal`: * 標準的 Python `Decimal`。 * 在請求與回應中,與 `float` 的處理方式相同。 -* 你可以在此查閱所有可用的 Pydantic 資料型別:Pydantic 資料型別。 +* 你可以在此查閱所有可用的 Pydantic 資料型別:[Pydantic 資料型別](https://docs.pydantic.dev/latest/usage/types/types/)。 ## 範例 { #example } diff --git a/docs/zh-hant/docs/tutorial/extra-models.md b/docs/zh-hant/docs/tutorial/extra-models.md index 8aae62f8e1..f5509f531f 100644 --- a/docs/zh-hant/docs/tutorial/extra-models.md +++ b/docs/zh-hant/docs/tutorial/extra-models.md @@ -12,7 +12,7 @@ 切勿儲存使用者的明文密碼。務必只儲存可供驗證的「安全雜湊」。 -若你還不清楚,稍後會在[安全性章節](security/simple-oauth2.md#password-hashing){.internal-link target=_blank}學到什麼是「密碼雜湊」。 +若你還不清楚,稍後會在[安全性章節](security/simple-oauth2.md#password-hashing)學到什麼是「密碼雜湊」。 /// @@ -162,11 +162,11 @@ UserInDB( 在 OpenAPI 中會以 `anyOf` 定義。 -要達成這點,使用標準的 Python 型別提示 `typing.Union`: +要達成這點,使用標準的 Python 型別提示 [`typing.Union`](https://docs.python.org/3/library/typing.html#typing.Union): /// note -在定義 `Union` 時,請先放置「更具體」的型別,再放「較不具體」的型別。以下範例中,較具體的 `PlaneItem` 置於 `CarItem` 之前:`Union[PlaneItem, CarItem]`。 +在定義 [`Union`](https://docs.pydantic.dev/latest/concepts/types/#unions) 時,請先放置「更具體」的型別,再放「較不具體」的型別。以下範例中,較具體的 `PlaneItem` 置於 `CarItem` 之前:`Union[PlaneItem, CarItem]`。 /// diff --git a/docs/zh-hant/docs/tutorial/first-steps.md b/docs/zh-hant/docs/tutorial/first-steps.md index 3aa2d39ae1..d6b1a72e32 100644 --- a/docs/zh-hant/docs/tutorial/first-steps.md +++ b/docs/zh-hant/docs/tutorial/first-steps.md @@ -11,7 +11,7 @@
```console -$ fastapi dev main.py +$ fastapi dev FastAPI Starting development server 🚀 @@ -58,7 +58,7 @@ INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) ### 查看它 { #check-it } -在瀏覽器中打開 http://127.0.0.1:8000. +在瀏覽器中打開 [http://127.0.0.1:8000](http://127.0.0.1:8000)。 你將看到如下的 JSON 回應: @@ -68,17 +68,17 @@ INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) ### 互動式 API 文件 { #interactive-api-docs } -現在,前往 http://127.0.0.1:8000/docs. +現在,前往 [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs)。 -你將看到自動的互動式 API 文件(由 Swagger UI 提供): +你將看到自動的互動式 API 文件(由 [Swagger UI](https://github.com/swagger-api/swagger-ui) 提供): ![Swagger UI](https://fastapi.tiangolo.com/img/index/index-01-swagger-ui-simple.png) ### 替代 API 文件 { #alternative-api-docs } -現在,前往 http://127.0.0.1:8000/redoc. +現在,前往 [http://127.0.0.1:8000/redoc](http://127.0.0.1:8000/redoc)。 -你將看到另一種自動文件(由 ReDoc 提供): +你將看到另一種自動文件(由 [ReDoc](https://github.com/Rebilly/ReDoc) 提供): ![ReDoc](https://fastapi.tiangolo.com/img/index/index-02-redoc-simple.png) @@ -92,7 +92,7 @@ INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) #### API 「schema」 { #api-schema } -在這種情況下,OpenAPI 是一個規範,它規定了如何定義 API 的 schema。 +在這種情況下,[OpenAPI](https://github.com/OAI/OpenAPI-Specification) 是一個規範,它規定了如何定義 API 的 schema。 這個 schema 定義包含了你的 API 路徑、可能接收的參數等內容。 @@ -110,7 +110,7 @@ OpenAPI 為你的 API 定義了 API 的 schema。而該 schema 會包含你的 A 如果你好奇原始的 OpenAPI schema 長什麼樣子,FastAPI 會自動生成一個包含所有 API 描述的 JSON(schema)。 -你可以直接在 http://127.0.0.1:8000/openapi.json 查看它。 +你可以直接在 [http://127.0.0.1:8000/openapi.json](http://127.0.0.1:8000/openapi.json) 查看它。 它會顯示一個 JSON,類似於: @@ -143,9 +143,58 @@ OpenAPI schema 驅動了兩個互動式文件系統。 你也可以用它自動生成程式碼,讓用戶端與你的 API 通訊。例如前端、手機或物聯網(IoT)應用程式。 +### 在 `pyproject.toml` 設定應用的 `entrypoint` { #configure-the-app-entrypoint-in-pyproject-toml } + +你可以在 `pyproject.toml` 中設定你的應用位置,例如: + +```toml +[tool.fastapi] +entrypoint = "main:app" +``` + +這個 `entrypoint` 會告訴 `fastapi` 指令應該用下面的方式匯入 app: + +```python +from main import app +``` + +如果你的程式碼結構像是: + +``` +. +├── backend +│   ├── main.py +│   ├── __init__.py +``` + +那你應該把 `entrypoint` 設為: + +```toml +[tool.fastapi] +entrypoint = "backend.main:app" +``` + +這等同於: + +```python +from backend.main import app +``` + +### 搭配路徑使用 `fastapi dev` { #fastapi-dev-with-path } + +你也可以把檔案路徑傳給 `fastapi dev` 指令,它會自動猜測要使用的 FastAPI app 物件: + +```console +$ fastapi dev main.py +``` + +但這樣每次執行 `fastapi` 指令時都要記得傳入正確路徑。 + +此外,其他工具可能找不到它,例如 [VS Code 擴充套件](../editor-support.md) 或 [FastAPI Cloud](https://fastapicloud.com),因此建議在 `pyproject.toml` 中使用 `entrypoint`。 + ### 部署你的應用程式(可選) { #deploy-your-app-optional } -你可以選擇將你的 FastAPI 應用程式部署到 FastAPI Cloud,如果還沒有,去加入候補名單吧。🚀 +你可以選擇將你的 FastAPI 應用程式部署到 [FastAPI Cloud](https://fastapicloud.com),如果還沒有,去加入候補名單吧。🚀 如果你已經有 **FastAPI Cloud** 帳號(我們已從候補名單邀請你 😉),你可以用一個指令部署你的應用程式。 @@ -191,7 +240,7 @@ Deploying to FastAPI Cloud... `FastAPI` 是一個直接繼承自 `Starlette` 的類別。 -你同樣可以透過 `FastAPI` 來使用 Starlette 所有的功能。 +你同樣可以透過 `FastAPI` 來使用 [Starlette](https://www.starlette.dev/) 所有的功能。 /// @@ -336,7 +385,7 @@ Python 中的 `@something` 語法被稱為「裝飾器」。 /// note -如果你不知道差別,請查看 [Async: *"In a hurry?"*](../async.md#in-a-hurry){.internal-link target=_blank}. +如果你不知道差別,請查看 [Async: *"In a hurry?"*](../async.md#in-a-hurry)。 /// @@ -352,11 +401,11 @@ Python 中的 `@something` 語法被稱為「裝飾器」。 ### 第六步:部署 { #step-6-deploy-it } -用一行指令將你的應用程式部署到 **FastAPI Cloud**:`fastapi deploy`。🎉 +用一行指令將你的應用程式部署到 **[FastAPI Cloud](https://fastapicloud.com)**:`fastapi deploy`。🎉 #### 關於 FastAPI Cloud { #about-fastapi-cloud } -**FastAPI Cloud** 由 **FastAPI** 的作者與團隊打造。 +**[FastAPI Cloud](https://fastapicloud.com)** 由 **FastAPI** 的作者與團隊打造。 它讓你以最小的成本完成 API 的**建置**、**部署**與**存取**流程。 diff --git a/docs/zh-hant/docs/tutorial/handling-errors.md b/docs/zh-hant/docs/tutorial/handling-errors.md index f3a7573cd5..b1ffd3e038 100644 --- a/docs/zh-hant/docs/tutorial/handling-errors.md +++ b/docs/zh-hant/docs/tutorial/handling-errors.md @@ -81,7 +81,7 @@ ## 安裝自訂例外處理器 { #install-custom-exception-handlers } -你可以使用 Starlette 的相同例外工具 來加入自訂例外處理器。 +你可以使用 [Starlette 的相同例外工具](https://www.starlette.dev/exceptions/) 來加入自訂例外處理器。 假設你有一個自訂例外 `UnicornException`,你(或你使用的函式庫)可能會 `raise` 它。 diff --git a/docs/zh-hant/docs/tutorial/index.md b/docs/zh-hant/docs/tutorial/index.md index 5e1961fd7b..3e5eed1bb7 100644 --- a/docs/zh-hant/docs/tutorial/index.md +++ b/docs/zh-hant/docs/tutorial/index.md @@ -15,7 +15,7 @@
```console -$ fastapi dev main.py +$ fastapi dev FastAPI Starting development server 🚀 @@ -42,12 +42,12 @@ $ fastapi dev INFO Will watch for changes in these directories: ['/home/user/code/awesomeapp'] - INFO Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C + INFO Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) - INFO Started reloader process [383138] using WatchFiles - INFO Started server process [383153] - INFO Waiting for application startup. - INFO Application startup complete. + INFO Started reloader process [383138] using WatchFiles + INFO Started server process [383153] + INFO Waiting for application startup. + INFO Application startup complete. ```
@@ -62,7 +62,7 @@ $ fastapi dev @@ -76,7 +76,7 @@ $ pip install "fastapi[standard]" /// note | 注意 -當你使用 `pip install "fastapi[standard]"` 安裝時,會包含一些預設的可選標準依賴項,其中包括 `fastapi-cloud-cli`,它可以讓你部署到 FastAPI Cloud。 +當你使用 `pip install "fastapi[standard]"` 安裝時,會包含一些預設的可選標準依賴項,其中包括 `fastapi-cloud-cli`,它可以讓你部署到 [FastAPI Cloud](https://fastapicloud.com)。 如果你不想包含那些可選的依賴項,你可以改為安裝 `pip install fastapi`。 @@ -84,6 +84,12 @@ $ pip install "fastapi[standard]" /// +/// tip + +FastAPI 提供了 [VS Code 官方擴充功能](https://marketplace.visualstudio.com/items?itemName=FastAPILabs.fastapi-vscode)(以及 Cursor),包含許多功能,例如路徑操作探索器、路徑操作搜尋、測試中的 CodeLens 導航(從測試跳到定義)、以及 FastAPI Cloud 的部署與日誌,全部可直接在你的編輯器中完成。 + +/// + ## 進階使用者指南 { #advanced-user-guide } 還有一個**進階使用者指南**你可以在讀完這個**教學 - 使用者指南**後再閱讀。 diff --git a/docs/zh-hant/docs/tutorial/middleware.md b/docs/zh-hant/docs/tutorial/middleware.md index ac6f5367d0..42a922d354 100644 --- a/docs/zh-hant/docs/tutorial/middleware.md +++ b/docs/zh-hant/docs/tutorial/middleware.md @@ -15,7 +15,7 @@ 如果你有使用帶有 `yield` 的相依性,其釋放階段的程式碼會在中介軟體之後執行。 -若有背景工作(在[背景工作](background-tasks.md){.internal-link target=_blank}一節會介紹,你稍後會看到),它們會在所有中介軟體之後執行。 +若有背景工作(在[背景工作](background-tasks.md)一節會介紹,你稍後會看到),它們會在所有中介軟體之後執行。 /// @@ -35,9 +35,9 @@ /// tip -請記得,自訂的非標準標頭可以使用 `X-` 前綴。 +請記得,自訂的非標準標頭可以[使用 `X-` 前綴](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers)。 -但如果你有自訂標頭並希望瀏覽器端的用戶端能看到它們,你需要在 CORS 設定([CORS(Cross-Origin Resource Sharing)](cors.md){.internal-link target=_blank})中使用 Starlette 的 CORS 文件所記載的參數 `expose_headers` 將它們加入。 +但如果你有自訂標頭並希望瀏覽器端的用戶端能看到它們,你需要在 CORS 設定([CORS(跨來源資源共用)](cors.md))中使用 [Starlette 的 CORS 文件](https://www.starlette.dev/middleware/#corsmiddleware)所記載的參數 `expose_headers` 將它們加入。 /// @@ -61,7 +61,7 @@ /// tip -這裡我們使用 `time.perf_counter()` 而不是 `time.time()`,因為在這些用例中它可能更精確。🤓 +這裡我們使用 [`time.perf_counter()`](https://docs.python.org/3/library/time.html#time.perf_counter) 而不是 `time.time()`,因為在這些用例中它可能更精確。🤓 /// @@ -90,6 +90,6 @@ app.add_middleware(MiddlewareB) ## 其他中介軟體 { #other-middlewares } -你之後可以在[進階使用者指南:進階中介軟體](../advanced/middleware.md){.internal-link target=_blank}閱讀更多關於其他中介軟體的內容。 +你之後可以在[進階使用者指南:進階中介軟體](../advanced/middleware.md)閱讀更多關於其他中介軟體的內容。 下一節你將會讀到如何使用中介軟體處理 CORS。 diff --git a/docs/zh-hant/docs/tutorial/path-params.md b/docs/zh-hant/docs/tutorial/path-params.md index 373f430cde..d46e32bb14 100644 --- a/docs/zh-hant/docs/tutorial/path-params.md +++ b/docs/zh-hant/docs/tutorial/path-params.md @@ -6,7 +6,7 @@ 路徑參數 `item_id` 的值會作為引數 `item_id` 傳入你的函式。 -所以,如果你執行這個範例並前往 http://127.0.0.1:8000/items/foo,你會看到這樣的回應: +所以,如果你執行這個範例並前往 [http://127.0.0.1:8000/items/foo](http://127.0.0.1:8000/items/foo),你會看到這樣的回應: ```JSON {"item_id":"foo"} @@ -28,7 +28,7 @@ ## 資料 轉換 { #data-conversion } -如果你執行這個範例並在瀏覽器開啟 http://127.0.0.1:8000/items/3,你會看到這樣的回應: +如果你執行這個範例並在瀏覽器開啟 [http://127.0.0.1:8000/items/3](http://127.0.0.1:8000/items/3),你會看到這樣的回應: ```JSON {"item_id":3} @@ -44,7 +44,7 @@ ## 資料驗證 { #data-validation } -但如果你在瀏覽器前往 http://127.0.0.1:8000/items/foo,你會看到漂亮的 HTTP 錯誤: +但如果你在瀏覽器前往 [http://127.0.0.1:8000/items/foo](http://127.0.0.1:8000/items/foo),你會看到漂亮的 HTTP 錯誤: ```JSON { @@ -64,7 +64,7 @@ 因為路徑參數 `item_id` 的值是 `"foo"`,它不是 `int`。 -同樣的錯誤也會在你提供 `float` 而不是 `int` 時出現,例如:http://127.0.0.1:8000/items/4.2 +同樣的錯誤也會在你提供 `float` 而不是 `int` 時出現,例如:[http://127.0.0.1:8000/items/4.2](http://127.0.0.1:8000/items/4.2) /// check @@ -78,7 +78,7 @@ ## 文件 { #documentation } -當你在瀏覽器開啟 http://127.0.0.1:8000/docs,你會看到自動產生、可互動的 API 文件,例如: +當你在瀏覽器開啟 [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs),你會看到自動產生、可互動的 API 文件,例如: @@ -92,9 +92,9 @@ ## 基於標準的優勢與替代文件 { #standards-based-benefits-alternative-documentation } -而且因為產生的 schema 來自 OpenAPI 標準,有很多相容的工具可用。 +而且因為產生的 schema 來自 [OpenAPI](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md) 標準,有很多相容的工具可用。 -因此,**FastAPI** 本身也提供另一種 API 文件(使用 ReDoc),你可以在 http://127.0.0.1:8000/redoc 存取: +因此,**FastAPI** 本身也提供另一種 API 文件(使用 ReDoc),你可以在 [http://127.0.0.1:8000/redoc](http://127.0.0.1:8000/redoc) 存取: @@ -102,7 +102,7 @@ ## Pydantic { #pydantic } -所有資料驗證都由 Pydantic 在底層處理,因此你能直接受惠。而且你可以放心使用。 +所有資料驗證都由 [Pydantic](https://docs.pydantic.dev/) 在底層處理,因此你能直接受惠。而且你可以放心使用。 你可以用相同的型別宣告搭配 `str`、`float`、`bool` 與許多更複雜的資料型別。 diff --git a/docs/zh-hant/docs/tutorial/query-params-str-validations.md b/docs/zh-hant/docs/tutorial/query-params-str-validations.md index ea84234c0e..372b26e4dd 100644 --- a/docs/zh-hant/docs/tutorial/query-params-str-validations.md +++ b/docs/zh-hant/docs/tutorial/query-params-str-validations.md @@ -157,7 +157,7 @@ q: str = Query(default="rick") 若不使用 `Annotated`、改用「(舊式)預設值」寫法,你在沒有 FastAPI 的「其他地方」呼叫該函式時,就得「記得」傳入正確參數,否則值會和預期不同(例如會得到 `QueryInfo` 或類似的東西,而不是 `str`)。你的編輯器不會提示,Python 執行該函式時也不會抱怨,只有在內部操作失敗時才會出錯。 -因為 `Annotated` 可以有多個中繼資料註解,你甚至可以用同一個函式配合其他工具,例如 Typer。🚀 +因為 `Annotated` 可以有多個中繼資料註解,你甚至可以用同一個函式配合其他工具,例如 [Typer](https://typer.tiangolo.com/)。🚀 ## 加入更多驗證 { #add-more-validations } @@ -369,11 +369,11 @@ http://127.0.0.1:8000/items/?item-query=foobaritems 這種情況下,你可以使用「自訂驗證函式」,它會在一般驗證之後套用(例如先確認值是 `str` 之後)。 -你可以在 `Annotated` 中使用 Pydantic 的 `AfterValidator` 來達成。 +你可以在 `Annotated` 中使用 [Pydantic 的 `AfterValidator`](https://docs.pydantic.dev/latest/concepts/validators/#field-after-validator) 來達成。 /// tip | 提示 -Pydantic 也有 `BeforeValidator` 等等。🤓 +Pydantic 也有 [`BeforeValidator`](https://docs.pydantic.dev/latest/concepts/validators/#field-before-validator) 等等。🤓 /// diff --git a/docs/zh-hant/docs/tutorial/request-forms.md b/docs/zh-hant/docs/tutorial/request-forms.md index 733a3e2869..d38db96f1a 100644 --- a/docs/zh-hant/docs/tutorial/request-forms.md +++ b/docs/zh-hant/docs/tutorial/request-forms.md @@ -4,9 +4,9 @@ /// info -要使用表單,請先安裝 `python-multipart`。 +要使用表單,請先安裝 [`python-multipart`](https://github.com/Kludex/python-multipart)。 -請先建立並啟用一個[虛擬環境](../virtual-environments.md){.internal-link target=_blank},然後再安裝,例如: +請先建立並啟用一個[虛擬環境](../virtual-environments.md),然後再安裝,例如: ```console $ pip install python-multipart @@ -56,7 +56,7 @@ HTML 表單(`
`)向伺服器傳送資料時,通常會使用一 但當表單包含檔案時,會使用 `multipart/form-data`。你會在下一章閱讀如何處理檔案。 -若想進一步了解這些編碼與表單欄位,請參考 MDNPOST 網頁文件。 +若想進一步了解這些編碼與表單欄位,請參考 [MDN web docs 的 `POST`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST)。 /// diff --git a/docs/zh-hant/docs/tutorial/response-model.md b/docs/zh-hant/docs/tutorial/response-model.md index d22402e180..d9ad9d9d15 100644 --- a/docs/zh-hant/docs/tutorial/response-model.md +++ b/docs/zh-hant/docs/tutorial/response-model.md @@ -13,6 +13,7 @@ FastAPI 會使用這個回傳型別來: * 在 OpenAPI 的「路徑操作」中為回應新增 JSON Schema。 * 這會被自動文件使用。 * 也會被自動用戶端程式碼產生工具使用。 +* 使用 Pydantic 將回傳資料**序列化**為 JSON,而 Pydantic 是用 **Rust** 撰寫的,因此會 **更快很多**。 但更重要的是: @@ -73,9 +74,9 @@ FastAPI 會使用這個 `response_model` 來做所有的資料文件、驗證等 /// info | 說明 -要使用 `EmailStr`,請先安裝 `email-validator`。 +要使用 `EmailStr`,請先安裝 [`email-validator`](https://github.com/JoshData/python-email-validator)。 -請先建立一個[虛擬環境](../virtual-environments.md){.internal-link target=_blank}、啟用它,然後安裝,例如: +請先建立一個[虛擬環境](../virtual-environments.md)、啟用它,然後安裝,例如: ```console $ pip install email-validator @@ -181,7 +182,7 @@ FastAPI 在內部會搭配 Pydantic 做一些事情,來確保不會把類別 ### 直接回傳 Response { #return-a-response-directly } -最常見的情況是[直接回傳 Response(在進階文件中稍後會解釋)](../advanced/response-directly.md){.internal-link target=_blank}。 +最常見的情況是[直接回傳 Response(在進階文件中稍後會解釋)](../advanced/response-directly.md)。 {* ../../docs_src/response_model/tutorial003_02_py310.py hl[8,10:11] *} @@ -257,7 +258,7 @@ FastAPI 在內部會搭配 Pydantic 做一些事情,來確保不會把類別 * `response_model_exclude_defaults=True` * `response_model_exclude_none=True` -如 Pydantic 文件中對 `exclude_defaults` 與 `exclude_none` 的說明。 +如 [Pydantic 文件](https://docs.pydantic.dev/1.10/usage/exporting_models/#modeldict)中對 `exclude_defaults` 與 `exclude_none` 的說明。 /// diff --git a/docs/zh-hant/docs/tutorial/response-status-code.md b/docs/zh-hant/docs/tutorial/response-status-code.md index cbcc67ca55..9ac2e41dab 100644 --- a/docs/zh-hant/docs/tutorial/response-status-code.md +++ b/docs/zh-hant/docs/tutorial/response-status-code.md @@ -20,7 +20,7 @@ /// info | 資訊 -`status_code` 也可以接收一個 `IntEnum`,例如 Python 的 `http.HTTPStatus`。 +`status_code` 也可以接收一個 `IntEnum`,例如 Python 的 [`http.HTTPStatus`](https://docs.python.org/3/library/http.html#http.HTTPStatus)。 /// @@ -66,7 +66,7 @@ FastAPI 知道這點,並會產生聲明「無回應本文」的 OpenAPI 文件 /// tip | 提示 -想深入瞭解各狀態碼與其用途,請參考 MDN 關於 HTTP 狀態碼的文件。 +想深入瞭解各狀態碼與其用途,請參考 [MDN 關於 HTTP 狀態碼的文件](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)。 /// @@ -98,4 +98,4 @@ FastAPI 知道這點,並會產生聲明「無回應本文」的 OpenAPI 文件 ## 變更預設值 { #changing-the-default } -稍後在 [進階使用者指南](../advanced/response-change-status-code.md){.internal-link target=_blank} 中,你會看到如何回傳一個不同於此處所宣告預設值的狀態碼。 +稍後在 [進階使用者指南](../advanced/response-change-status-code.md) 中,你會看到如何回傳一個不同於此處所宣告預設值的狀態碼。 diff --git a/docs/zh-hant/docs/virtual-environments.md b/docs/zh-hant/docs/virtual-environments.md index 74b8b9f8c8..33bf3d8140 100644 --- a/docs/zh-hant/docs/virtual-environments.md +++ b/docs/zh-hant/docs/virtual-environments.md @@ -22,7 +22,7 @@ 這個頁面將教你如何使用**虛擬環境**以及了解它們的工作原理。 -如果你計畫使用一個**可以為你管理一切的工具**(包括安裝 Python),試試 uv。 +如果你計畫使用一個**可以為你管理一切的工具**(包括安裝 Python),試試 [uv](https://github.com/astral-sh/uv)。 /// @@ -86,7 +86,7 @@ $ python -m venv .venv //// tab | `uv` -如果你安裝了 `uv`,你也可以使用它來建立一個虛擬環境。 +如果你安裝了 [`uv`](https://github.com/astral-sh/uv),你也可以使用它來建立一個虛擬環境。
@@ -150,7 +150,7 @@ $ .venv\Scripts\Activate.ps1 //// tab | Windows Bash -或者,如果你在 Windows 上使用 Bash(例如 Git Bash): +或者,如果你在 Windows 上使用 Bash(例如 [Git Bash](https://gitforwindows.org/)):
@@ -216,7 +216,7 @@ C:\Users\user\code\awesome-project\.venv\Scripts\python /// tip -如果你使用 `uv` 來安裝內容,而不是 `pip`,那麼你就不需要升級 `pip`。😎 +如果你使用 [`uv`](https://github.com/astral-sh/uv) 來安裝內容,而不是 `pip`,那麼你就不需要升級 `pip`。😎 /// @@ -268,7 +268,7 @@ $ python -m ensurepip --upgrade /// tip -如果你使用 `uv` 來建立虛擬環境,它會自動為你完成這個操作,你可以跳過這一步。😎 +如果你使用 [`uv`](https://github.com/astral-sh/uv) 來建立虛擬環境,它會自動為你完成這個操作,你可以跳過這一步。😎 /// @@ -340,7 +340,7 @@ $ pip install "fastapi[standard]" //// tab | `uv` -如果你有 `uv`: +如果你有 [`uv`](https://github.com/astral-sh/uv):
@@ -372,7 +372,7 @@ $ pip install -r requirements.txt //// tab | `uv` -如果你有 `uv`: +如果你有 [`uv`](https://github.com/astral-sh/uv):
@@ -416,8 +416,8 @@ Hello World 例如: -* VS Code -* PyCharm +* [VS Code](https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment) +* [PyCharm](https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html) /// tip @@ -455,7 +455,7 @@ $ deactivate ## 為什麼要使用虛擬環境 { #why-virtual-environments } -你需要安裝 Python 才能使用 FastAPI。 +你需要安裝 [Python](https://www.python.org/) 才能使用 FastAPI。 接下來,你需要**安裝** FastAPI 以及你想使用的其他**套件**。 @@ -564,7 +564,7 @@ $ pip install "fastapi[standard]"
-這會從 PyPI 下載一個壓縮檔案,其中包含 FastAPI 的程式碼。 +這會從 [PyPI](https://pypi.org/project/fastapi/) 下載一個壓縮檔案,其中包含 FastAPI 的程式碼。 它還會**下載** FastAPI 所依賴的其他套件的檔案。 @@ -627,7 +627,7 @@ $ .venv\Scripts\Activate.ps1 //// tab | Windows Bash -或者如果你在 Windows 上使用 Bash(例如 Git Bash): +或者如果你在 Windows 上使用 Bash(例如 [Git Bash](https://gitforwindows.org/)):
@@ -819,7 +819,7 @@ Traceback (most recent call last):
-但如果你停用虛擬環境並啟用 `prisoner-of-askaban` 的新虛擬環境,那麼當你執行 `python` 時,它會使用 `prisoner-of-askaban` 中虛擬環境的 Python。 +但如果你停用虛擬環境並啟用 `prisoner-of-azkaban` 的新虛擬環境,那麼當你執行 `python` 時,它會使用 `prisoner-of-azkaban` 中虛擬環境的 Python。
@@ -846,7 +846,7 @@ I solemnly swear 🐺 有許多**替代方案**來管理虛擬環境、套件依賴(requirements)、專案。 -當你準備好並想要使用一個工具來**管理整個專案**、套件依賴、虛擬環境等,建議你嘗試 uv。 +當你準備好並想要使用一個工具來**管理整個專案**、套件依賴、虛擬環境等,建議你嘗試 [uv](https://github.com/astral-sh/uv)。 `uv` 可以執行許多操作,它可以: