Search Options

Display Count
Sort
Preferred Language
Advanced Search

Results 121 - 130 of 981 for tutorial002_py310 (0.11 seconds)

  1. docs/zh/docs/advanced/additional-responses.md

    你可以使用同一个 `responses` 参数为同一个主响应添加不同的媒体类型。
    
    例如,你可以添加一个额外的媒体类型 `image/png`,声明你的*路径操作*可以返回 JSON 对象(媒体类型为 `application/json`)或 PNG 图片:
    
    {* ../../docs_src/additional_responses/tutorial002_py310.py hl[17:22,26] *}
    
    /// note | 注意
    
    请注意,你必须直接使用 `FileResponse` 返回图片。
    
    ///
    
    /// info | 信息
    
    除非你在 `responses` 参数中明确指定不同的媒体类型,否则 FastAPI 会假设响应与主响应类具有相同的媒体类型(默认是 `application/json`)。
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 17:06:37 GMT 2026
    - 8.7K bytes
    - Click Count (0)
  2. docs/zh-hant/docs/tutorial/body-multiple-params.md

    ```JSON
    {
        "name": "Foo",
        "description": "The pretender",
        "price": 42.0,
        "tax": 3.2
    }
    ```
    
    但你也可以宣告多個 Body 參數,例如 `item` 與 `user`:
    
    {* ../../docs_src/body_multiple_params/tutorial002_py310.py hl[20] *}
    
    在此情況下,**FastAPI** 會注意到函式中有多個 Body 參數(有兩個參數是 Pydantic 模型)。
    
    因此,它會使用參數名稱作為 body 中的鍵(欄位名稱),並期望如下的主體:
    
    ```JSON
    {
        "item": {
            "name": "Foo",
            "description": "The pretender",
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Sat Feb 14 08:15:26 GMT 2026
    - 4.6K bytes
    - Click Count (0)
  3. docs/zh/docs/tutorial/body-nested-models.md

    对具有内部类型的模型属性也使用相同的标准语法。
    
    因此,在我们的示例中,我们可以将 `tags` 明确地指定为一个「字符串列表」:
    
    {* ../../docs_src/body_nested_models/tutorial002_py310.py hl[12] *}
    
    ## Set 类型 { #set-types }
    
    但是随后我们考虑了一下,意识到标签不应该重复,它们很大可能会是唯一的字符串。
    
    而 Python 有一种用于保存唯一元素集合的特殊数据类型 `set`。
    
    然后我们可以将 `tags` 声明为一个由字符串组成的 set:
    
    {* ../../docs_src/body_nested_models/tutorial003_py310.py hl[12] *}
    
    这样,即使你收到带有重复数据的请求,这些数据也会被转换为一组唯一项。
    
    而且,每当你输出该数据时,即使源数据有重复,它们也将作为一组唯一项输出。
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 17:06:37 GMT 2026
    - 6.8K bytes
    - Click Count (0)
  4. docs/en/docs/tutorial/path-params.md

    {* ../../docs_src/path_params/tutorial005_py310.py hl[17] *}
    
    #### Get the *enumeration value* { #get-the-enumeration-value }
    
    You can get the actual value (a `str` in this case) using `model_name.value`, or in general, `your_enum_member.value`:
    
    {* ../../docs_src/path_params/tutorial005_py310.py hl[20] *}
    
    /// tip
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 05 18:13:19 GMT 2026
    - 8.8K bytes
    - Click Count (0)
  5. docs/zh-hant/docs/tutorial/path-params-numeric-validations.md

    如果你把有「預設值」的參數放在沒有「預設值」的參數之前,Python 會抱怨。
    
    但你可以調整它們的順序,先放沒有預設值(查詢參數 `q`)的參數。
    
    對 **FastAPI** 來說沒差。它會依參數名稱、型別與預設宣告(`Query`、`Path` 等)來辨識參數,並不在意順序。
    
    因此,你可以這樣宣告你的函式:
    
    {* ../../docs_src/path_params_numeric_validations/tutorial002_py310.py hl[7] *}
    
    但請記住,若使用 `Annotated`,你就不會有這個問題,因為你不是用函式參數預設值來放 `Query()` 或 `Path()`。
    
    {* ../../docs_src/path_params_numeric_validations/tutorial002_an_py310.py *}
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 17:05:38 GMT 2026
    - 5.8K bytes
    - Click Count (0)
  6. docs/zh/docs/tutorial/path-params.md

    {* ../../docs_src/path_params/tutorial001_py310.py hl[6:7] *}
    
    路径参数 `item_id` 的值会作为参数 `item_id` 传递给你的函数。
    
    运行示例并访问 [http://127.0.0.1:8000/items/foo](http://127.0.0.1:8000/items/foo),可获得如下响应:
    
    ```JSON
    {"item_id":"foo"}
    ```
    
    ## 声明路径参数的类型 { #path-parameters-with-types }
    
    使用 Python 标准类型注解,声明路径操作函数中路径参数的类型:
    
    {* ../../docs_src/path_params/tutorial002_py310.py hl[7] *}
    
    本例把 `item_id` 的类型声明为 `int`。
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 17:06:37 GMT 2026
    - 7.6K bytes
    - Click Count (0)
  7. docs/en/docs/python-types.md

    {* ../../docs_src/python_types/tutorial003_py310.py hl[1] *}
    
    Because the editor knows the types of the variables, you don't only get completion, you also get error checks:
    
    <img src="/img/python-types/image04.png">
    
    Now you know that you have to fix it, convert `age` to a string with `str(age)`:
    
    {* ../../docs_src/python_types/tutorial004_py310.py hl[2] *}
    
    ## Declaring types { #declaring-types }
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 05 18:13:19 GMT 2026
    - 11K bytes
    - Click Count (0)
  8. docs/ja/docs/advanced/additional-responses.md

    同じ `responses` パラメータを使って、同一のメインレスポンスに別のメディアタイプを追加できます。
    
    例えば、`image/png` の追加メディアタイプを加え、あなたの *path operation* が JSON オブジェクト(メディアタイプ `application/json`)または PNG 画像を返せることを宣言できます:
    
    {* ../../docs_src/additional_responses/tutorial002_py310.py hl[17:22,26] *}
    
    /// note | 備考
    
    画像は `FileResponse` を使って直接返す必要がある点に注意してください。
    
    ///
    
    /// info | 情報
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 14:07:17 GMT 2026
    - 10K bytes
    - Click Count (0)
  9. docs/en/docs/tutorial/handling-errors.md

    You probably won't need to use it directly in your code.
    
    But in case you needed it for an advanced scenario, you can add custom headers:
    
    {* ../../docs_src/handling_errors/tutorial002_py310.py hl[14] *}
    
    ## Install custom exception handlers { #install-custom-exception-handlers }
    
    You can add custom exception handlers with [the same exception utilities from Starlette](https://www.starlette.dev/exceptions/).
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 05 18:13:19 GMT 2026
    - 8.9K bytes
    - Click Count (0)
  10. docs/en/docs/advanced/generate-clients.md

    For example, you could have a section for **items** and another section for **users**, and they could be separated by tags:
    
    {* ../../docs_src/generate_clients/tutorial002_py310.py hl[21,26,34] *}
    
    ### Generate a TypeScript Client with Tags { #generate-a-typescript-client-with-tags }
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 05 18:13:19 GMT 2026
    - 9.7K bytes
    - Click Count (1)
Back to Top