Search Options

Results per page
Sort
Preferred Languages
Advance

Results 51 - 60 of 386 for notes (0.14 sec)

  1. docs/zh/docs/tutorial/handling-errors.md

    但该异常将会被 `unicorn_exception_handler` 处理。
    
    接收到的错误信息清晰明了,HTTP 状态码为 `418`,JSON 内容如下:
    
    ```JSON
    {"message": "Oops! yolo did something. There goes a rainbow..."}
    
    ```
    
    !!! note "技术细节"
    
        `from starlette.requests import Request` 和 `from starlette.responses import JSONResponse` 也可以用于导入 `Request` 和 `JSONResponse`。
    
    Plain Text
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Fri Mar 22 01:42:11 GMT 2024
    - 8.4K bytes
    - Viewed (0)
  2. docs/zh/docs/advanced/response-directly.md

    对于这些情况,在将数据传递给响应之前,你可以使用 `jsonable_encoder` 来转换你的数据。
    
    
    ```Python hl_lines="4 6 20 21"
    {!../../../docs_src/response_directly/tutorial001.py!}
    ```
    
    !!! note "技术细节"
        你也可以使用 `from starlette.responses import JSONResponse`。
    
        出于方便,**FastAPI** 会提供与 `starlette.responses` 相同的 `fastapi.responses` 给开发者。但是大多数可用的响应都直接来自 Starlette。
    
    ## 返回自定义 `Response`
    
    Plain Text
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Thu May 12 00:06:16 GMT 2022
    - 3.1K bytes
    - Viewed (0)
  3. tests/test_request_body_parameters_media_type.py

    import typing
    
    from fastapi import Body, FastAPI
    from fastapi.testclient import TestClient
    from pydantic import BaseModel
    
    app = FastAPI()
    
    media_type = "application/vnd.api+json"
    
    
    # NOTE: These are not valid JSON:API resources
    # but they are fine for testing requestBody with custom media_type
    class Product(BaseModel):
        name: str
        price: float
    
    
    class Shop(BaseModel):
        name: str
    
    
    @app.post("/products")
    Python
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Fri Jul 07 17:12:13 GMT 2023
    - 6.4K bytes
    - Viewed (0)
  4. docs/zh/docs/tutorial/response-model.md

        {!> ../../../docs_src/response_model/tutorial001_py39.py!}
        ```
    
    === "Python 3.8+"
    
        ```Python hl_lines="17  22  24-27"
        {!> ../../../docs_src/response_model/tutorial001.py!}
        ```
    
    !!! note
        注意,`response_model`是「装饰器」方法(`get`,`post` 等)的一个参数。不像之前的所有参数和请求体,它不属于*路径操作函数*。
    
    它接收的类型与你将为 Pydantic 模型属性所声明的类型相同,因此它可以是一个 Pydantic 模型,但也可以是一个由 Pydantic 模型组成的 `list`,例如 `List[Item]`。
    
    FastAPI 将使用此 `response_model` 来:
    
    Plain Text
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Fri Mar 22 01:42:11 GMT 2024
    - 7.9K bytes
    - Viewed (0)
  5. docs/en/docs/tutorial/body-fields.md

        ```Python hl_lines="11-14"
        {!> ../../../docs_src/body_fields/tutorial001.py!}
        ```
    
    `Field` works the same way as `Query`, `Path` and `Body`, it has all the same parameters, etc.
    
    !!! note "Technical Details"
        Actually, `Query`, `Path` and others you'll see next create objects of subclasses of a common `Param` class, which is itself a subclass of Pydantic's `FieldInfo` class.
    
    Plain Text
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Tue Oct 17 05:59:11 GMT 2023
    - 3.6K bytes
    - Viewed (0)
  6. docs/en/docs/advanced/middleware.md

    ## Integrated middlewares
    
    **FastAPI** includes several middlewares for common use cases, we'll see next how to use them.
    
    !!! note "Technical Details"
        For the next examples, you could also use `from starlette.middleware.something import SomethingMiddleware`.
    
    Plain Text
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Fri Mar 10 18:27:10 GMT 2023
    - 4K bytes
    - Viewed (0)
  7. docs/zh/docs/tutorial/body-fields.md

            Prefer to use the `Annotated` version if possible.
    
        ```Python hl_lines="11-14"
        {!> ../../../docs_src/body_fields/tutorial001.py!}
        ```
    
    `Field` 的工作方式和 `Query`、`Path`、`Body` 相同,参数也相同。
    
    !!! note "技术细节"
    
        实际上,`Query`、`Path` 都是 `Params` 的子类,而 `Params` 类又是 Pydantic 中 `FieldInfo` 的子类。
    
        Pydantic 的 `Field` 返回也是 `FieldInfo` 的类实例。
    
        `Body` 直接返回的也是 `FieldInfo` 的子类的对象。后文还会介绍一些 `Body` 的子类。
    
    Plain Text
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Mon Apr 01 05:35:27 GMT 2024
    - 3K bytes
    - Viewed (0)
  8. docs/em/docs/tutorial/handling-errors.md

    ✋️ ⚫️ 🔜 🍵 `unicorn_exception_handler`.
    
    , 👆 🔜 📨 🧹 ❌, ⏮️ 🇺🇸🔍 👔 📟 `418` & 🎻 🎚:
    
    ```JSON
    {"message": "Oops! yolo did something. There goes a rainbow..."}
    ```
    
    !!! note "📡 ℹ"
        👆 💪 ⚙️ `from starlette.requests import Request` & `from starlette.responses import JSONResponse`.
    
    Plain Text
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Fri Mar 22 01:42:11 GMT 2024
    - 8.3K bytes
    - Viewed (0)
  9. docs/zh/docs/advanced/custom-request-and-route.md

    `APIRoute.get_route_handler()` 方法返回的是函数,并且返回的函数接收请求并返回响应。
    
    本例用它根据原始请求创建 `GzipRequest`。
    
    ```Python hl_lines="18-26"
    {!../../../docs_src/custom_request_and_route/tutorial001.py!}
    ```
    
    !!! note "技术细节"
    
        `Request` 的 `request.scope` 属性是包含关联请求元数据的字典。
    
        `Request` 的 `request.receive` 方法是**接收**请求体的函数。
    
        `scope` 字典与 `receive` 函数都是 ASGI 规范的内容。
    
        `scope` 与 `receive` 也是创建新的 `Request` 实例所需的。
    
    Plain Text
    - Registered: Sun Mar 31 07:19:09 GMT 2024
    - Last Modified: Sat Mar 30 22:45:40 GMT 2024
    - 3.8K bytes
    - Viewed (0)
  10. docs/ja/docs/advanced/response-directly.md

    このようなケースでは、レスポンスにデータを含める前に `jsonable_encoder` を使ってデータを変換できます。
    
    ```Python hl_lines="6-7  21-22"
    {!../../../docs_src/response_directly/tutorial001.py!}
    ```
    
    !!! note "技術詳細"
        また、`from starlette.responses import JSONResponse` も利用できます。
    
        **FastAPI** は開発者の利便性のために `fastapi.responses` という `starlette.responses` と同じものを提供しています。しかし、利用可能なレスポンスのほとんどはStarletteから直接提供されます。
    
    ## カスタム `Response` を返す
    Plain Text
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Thu Nov 05 22:50:38 GMT 2020
    - 3.6K bytes
    - Viewed (0)
Back to top