@@ -199,7 +199,7 @@ async def read_item(item_id: int, q: str | None = None):
**注意**:
-如果你不確定,請查看文件中 _"In a hurry?"_ 章節的
。
+如果你不確定,請查看文件中 _"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.
。
+使用瀏覽器開啟 [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)。
-你會看到自動生成的互動式 API 文件(由
提供):
+你會看到自動生成的互動式 API 文件(由 [Swagger UI](https://github.com/swagger-api/swagger-ui) 提供):

### 替代 API 文件 { #alternative-api-docs }
-現在前往
。
+現在前往 [http://127.0.0.1:8000/redoc](http://127.0.0.1:8000/redoc)。
-你會看到另一種自動文件(由
提供):
+你會看到另一種自動文件(由 [ReDoc](https://github.com/Rebilly/ReDoc) 提供):

@@ -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)。
* 互動式 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)。
* 替代文件也會反映新的查詢參數與 body:
@@ -433,7 +433,7 @@ item: Item

-若想看包含更多功能的完整範例,請參考
** 系統。
* 安全與驗證,包含支援 **OAuth2** 搭配 **JWT tokens** 與 **HTTP Basic** 驗證。
* 宣告**深度巢狀 JSON 模型**的進階(但同樣簡單)技巧(感謝 Pydantic)。
-* 與
及其他函式庫的 **GraphQL** 整合。
+* 與 [Strawberry](https://strawberry.rocks) 及其他函式庫的 **GraphQL** 整合。
* 許多額外功能(感謝 Starlette),例如:
* **WebSockets**
* 基於 HTTPX 與 `pytest` 的極其簡單的測試
@@ -452,24 +452,10 @@ item: Item
### 部署你的應用(可選) { #deploy-your-app-optional }
-你也可以選擇將 FastAPI 應用部署到
,如果你還沒加入,去登記等候名單吧。🚀
+你也可以選擇將 FastAPI 應用部署到 [FastAPI Cloud](https://fastapicloud.com),如果你還沒加入,去登記等候名單吧。🚀
如果你已經有 **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) 提供):

### 替代 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) 提供):

@@ -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`。你會在下一章閱讀如何處理檔案。
-若想進一步了解這些編碼與表單欄位,請參考 MDN 的 POST 網頁文件。
+若想進一步了解這些編碼與表單欄位,請參考 [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` 可以執行許多操作,它可以: