Search Options

Results per page
Sort
Preferred Languages
Advance

Results 51 - 60 of 140 for kAsync (0.24 sec)

  1. docs/zh/docs/advanced/events.md

    # 事件:启动 - 关闭
    
    **FastAPI** 支持定义在应用启动前,或应用关闭后执行的事件处理器(函数)。
    
    事件函数既可以声明为异步函数(`async def`),也可以声明为普通函数(`def`)。
    
    !!! warning "警告"
    
        **FastAPI** 只执行主应用中的事件处理器,不执行[子应用 - 挂载](sub-applications.md){.internal-link target=_blank}中的事件处理器。
    
    ## `startup` 事件
    
    使用 `startup` 事件声明 `app` 启动前运行的函数:
    
    ```Python hl_lines="8"
    {!../../../docs_src/events/tutorial001.py!}
    ```
    
    本例中,`startup` 事件处理器函数为项目数据库(只是**字典**)提供了一些初始值。
    
    **FastAPI** 支持多个事件处理器函数。
    Registered: Mon Jun 17 08:32:26 UTC 2024
    - Last Modified: Thu Apr 18 19:53:19 UTC 2024
    - 1.7K bytes
    - Viewed (0)
  2. docs_src/custom_response/tutorial006c.py

    from fastapi import FastAPI
    from fastapi.responses import RedirectResponse
    
    app = FastAPI()
    
    
    @app.get("/pydantic", response_class=RedirectResponse, status_code=302)
    async def redirect_pydantic():
    Registered: Mon Jun 17 08:32:26 UTC 2024
    - Last Modified: Fri Mar 22 01:42:11 UTC 2024
    - 237 bytes
    - Viewed (0)
  3. docs_src/header_params/tutorial002.py

    from typing import Union
    
    from fastapi import FastAPI, Header
    
    app = FastAPI()
    
    
    @app.get("/items/")
    async def read_items(
        strange_header: Union[str, None] = Header(default=None, convert_underscores=False),
    ):
    Registered: Mon Jun 17 08:32:26 UTC 2024
    - Last Modified: Tue Mar 26 16:56:53 UTC 2024
    - 260 bytes
    - Viewed (0)
  4. docs_src/query_params_str_validations/tutorial014_py310.py

    from fastapi import FastAPI, Query
    
    app = FastAPI()
    
    
    @app.get("/items/")
    async def read_items(
        hidden_query: str | None = Query(default=None, include_in_schema=False),
    ):
        if hidden_query:
            return {"hidden_query": hidden_query}
        else:
    Registered: Mon Jun 17 08:32:26 UTC 2024
    - Last Modified: Tue Mar 26 16:56:53 UTC 2024
    - 298 bytes
    - Viewed (0)
  5. docs_src/dependencies/tutorial005_an.py

        q: Annotated[str, Depends(query_extractor)],
        last_query: Annotated[Union[str, None], Cookie()] = None,
    ):
        if not q:
            return last_query
        return q
    
    
    @app.get("/items/")
    async def read_query(
        query_or_default: Annotated[str, Depends(query_or_cookie_extractor)],
    ):
    Registered: Mon Jun 17 08:32:26 UTC 2024
    - Last Modified: Tue Mar 26 16:56:53 UTC 2024
    - 558 bytes
    - Viewed (0)
  6. docs_src/query_params_str_validations/tutorial014_an_py310.py

    from typing import Annotated
    
    from fastapi import FastAPI, Query
    
    app = FastAPI()
    
    
    @app.get("/items/")
    async def read_items(
        hidden_query: Annotated[str | None, Query(include_in_schema=False)] = None,
    ):
        if hidden_query:
            return {"hidden_query": hidden_query}
        else:
    Registered: Mon Jun 17 08:32:26 UTC 2024
    - Last Modified: Tue Mar 26 16:56:53 UTC 2024
    - 331 bytes
    - Viewed (0)
  7. docs_src/query_params_str_validations/tutorial014.py

    from typing import Union
    
    from fastapi import FastAPI, Query
    
    app = FastAPI()
    
    
    @app.get("/items/")
    async def read_items(
        hidden_query: Union[str, None] = Query(default=None, include_in_schema=False),
    ):
        if hidden_query:
            return {"hidden_query": hidden_query}
        else:
    Registered: Mon Jun 17 08:32:26 UTC 2024
    - Last Modified: Tue Mar 26 16:56:53 UTC 2024
    - 330 bytes
    - Viewed (0)
  8. docs_src/extra_data_types/tutorial001.py

    from datetime import datetime, time, timedelta
    from typing import Union
    from uuid import UUID
    
    from fastapi import Body, FastAPI
    
    app = FastAPI()
    
    
    @app.put("/items/{item_id}")
    async def read_items(
        item_id: UUID,
        start_datetime: datetime = Body(),
        end_datetime: datetime = Body(),
        process_after: timedelta = Body(),
        repeat_at: Union[time, None] = Body(default=None),
    ):
    Registered: Mon Jun 17 08:32:26 UTC 2024
    - Last Modified: Fri Apr 19 00:11:40 UTC 2024
    - 755 bytes
    - Viewed (0)
  9. 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: Mon Jun 17 08:32:26 UTC 2024
    - Last Modified: Tue Mar 26 16:56:53 UTC 2024
    - 343 bytes
    - Viewed (0)
  10. docs_src/query_params_str_validations/tutorial014_an.py

    from typing import Union
    
    from fastapi import FastAPI, Query
    from typing_extensions import Annotated
    
    app = FastAPI()
    
    
    @app.get("/items/")
    async def read_items(
        hidden_query: Annotated[Union[str, None], Query(include_in_schema=False)] = None,
    ):
        if hidden_query:
            return {"hidden_query": hidden_query}
        else:
    Registered: Mon Jun 17 08:32:26 UTC 2024
    - Last Modified: Tue Mar 26 16:56:53 UTC 2024
    - 373 bytes
    - Viewed (0)
Back to top