Search Options

Results per page
Sort
Preferred Languages
Advance

Results 21 - 30 of 110 for max_length (0.04 sec)

  1. docs_src/query_params_str_validations/tutorial003_an_py39.py

    from typing import Annotated, Union
    
    from fastapi import FastAPI, Query
    
    app = FastAPI()
    
    
    @app.get("/items/")
    async def read_items(
        q: Annotated[Union[str, None], Query(min_length=3, max_length=50)] = None,
    ):
        results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
        if q:
            results.update({"q": q})
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Tue Mar 26 16:56:53 UTC 2024
    - 343 bytes
    - Viewed (0)
  2. docs/zh/docs/tutorial/query-params-str-validations.md

    ...使得参数可选,等同于:
    
    ```Python
    q: str = None
    ```
    
    但是 `Query` 显式地将其声明为查询参数。
    
    然后,我们可以将更多的参数传递给 `Query`。在本例中,适用于字符串的 `max_length` 参数:
    
    ```Python
    q: Union[str, None] = Query(default=None, max_length=50)
    ```
    
    将会校验数据,在数据无效时展示清晰的错误信息,并在 OpenAPI 模式的*路径操作*中记录该参​​数。
    
    ## 添加更多校验
    
    你还可以添加 `min_length` 参数:
    
    {* ../../docs_src/query_params_str_validations/tutorial003.py hl[10] *}
    
    ## 添加正则表达式
    
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Feb 15 16:23:59 UTC 2025
    - 7.7K bytes
    - Viewed (0)
  3. docs_src/query_params_str_validations/tutorial010_an_py39.py

            Query(
                alias="item-query",
                title="Query string",
                description="Query string for the items to search in the database that have a good match",
                min_length=3,
                max_length=50,
                pattern="^fixedquery$",
                deprecated=True,
            ),
        ] = None,
    ):
        results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
        if q:
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Tue Oct 24 20:26:06 UTC 2023
    - 635 bytes
    - Viewed (0)
  4. docs_src/query_params_str_validations/tutorial010_py39.py

            default=None,
            alias="item-query",
            title="Query string",
            description="Query string for the items to search in the database that have a good match",
            min_length=3,
            max_length=50,
            pattern="^fixedquery$",
            deprecated=True,
        ),
    ):
        results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
        if q:
            results.update({"q": q})
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 20:41:43 UTC 2025
    - 574 bytes
    - Viewed (0)
  5. docs_src/query_params_str_validations/tutorial002_an_py310.py

    from typing import Annotated
    
    from fastapi import FastAPI, Query
    
    app = FastAPI()
    
    
    @app.get("/items/")
    async def read_items(q: Annotated[str | None, Query(max_length=50)] = None):
        results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
        if q:
            results.update({"q": q})
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Mar 18 12:29:59 UTC 2023
    - 309 bytes
    - Viewed (0)
  6. docs_src/query_params_str_validations/tutorial002_py39.py

    from typing import Union
    
    from fastapi import FastAPI, Query
    
    app = FastAPI()
    
    
    @app.get("/items/")
    async def read_items(q: Union[str, None] = Query(default=None, max_length=50)):
        results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
        if q:
            results.update({"q": q})
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 20:41:43 UTC 2025
    - 308 bytes
    - Viewed (0)
  7. tests/test_tutorial/test_query_params_str_validations/test_tutorial003.py

                {
                    "type": "string_too_long",
                    "loc": ["query", "q"],
                    "msg": "String should have at most 50 characters",
                    "input": "q" * 51,
                    "ctx": {"max_length": 50},
                }
            ]
        }
    
    
    def test_openapi_schema(client: TestClient):
        response = client.get("/openapi.json")
        assert response.status_code == 200, response.text
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Fri Dec 26 10:43:02 UTC 2025
    - 5.1K bytes
    - Viewed (0)
  8. docs/es/docs/tutorial/query-params-str-validations.md

    {* ../../docs_src/query_params_str_validations/tutorial002_an_py310.py hl[9] *}
    
    Nota que el valor por defecto sigue siendo `None`, por lo que el parámetro sigue siendo opcional.
    
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 20:41:43 UTC 2025
    - 18.4K bytes
    - Viewed (0)
  9. docs_src/body_fields/tutorial001_py310.py

    from pydantic import BaseModel, Field
    
    app = FastAPI()
    
    
    class Item(BaseModel):
        name: str
        description: str | None = Field(
            default=None, title="The description of the item", max_length=300
        )
        price: float = Field(gt=0, description="The price must be greater than zero")
        tax: float | None = None
    
    
    @app.put("/items/{item_id}")
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Fri May 13 23:38:22 UTC 2022
    - 523 bytes
    - Viewed (0)
  10. docs/ru/docs/tutorial/query-params-str-validations.md

    {* ../../docs_src/query_params_str_validations/tutorial002_an_py310.py hl[9] *}
    
    Обратите внимание, что значение по умолчанию по‑прежнему `None`, то есть параметр остаётся необязательным.
    
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 20:41:43 UTC 2025
    - 26.2K bytes
    - Viewed (0)
Back to top