Search Options

Results per page
Sort
Preferred Languages
Advance

Results 181 - 190 of 421 for depende (0.07 sec)

  1. docs_src/dependencies/tutorial008c_an_py39.py

    from typing import Annotated
    
    from fastapi import Depends, FastAPI, HTTPException
    
    app = FastAPI()
    
    
    class InternalError(Exception):
        pass
    
    
    def get_username():
        try:
            yield "Rick"
        except InternalError:
            print("Oops, we didn't raise again, Britney ๐Ÿ˜ฑ")
    
    
    @app.get("/items/{item_id}")
    def get_item(item_id: str, username: Annotated[str, Depends(get_username)]):
        if item_id == "portal-gun":
    Registered: Sun Oct 27 07:19:11 UTC 2024
    - Last Modified: Sat Feb 24 23:06:37 UTC 2024
    - 700 bytes
    - Viewed (0)
  2. docs_src/background_tasks/tutorial002_an.py

    from typing import Union
    
    from fastapi import BackgroundTasks, Depends, FastAPI
    from typing_extensions import Annotated
    
    app = FastAPI()
    
    
    def write_log(message: str):
        with open("log.txt", mode="a") as log:
            log.write(message)
    
    
    def get_query(background_tasks: BackgroundTasks, q: Union[str, None] = None):
        if q:
            message = f"found query: {q}\n"
            background_tasks.add_task(write_log, message)
        return q
    Registered: Sun Oct 27 07:19:11 UTC 2024
    - Last Modified: Sat Mar 18 12:29:59 UTC 2023
    - 725 bytes
    - Viewed (0)
  3. tests/test_security_api_key_header_optional.py

    from typing import Optional
    
    from fastapi import Depends, FastAPI, Security
    from fastapi.security import APIKeyHeader
    from fastapi.testclient import TestClient
    from pydantic import BaseModel
    
    app = FastAPI()
    
    api_key = APIKeyHeader(name="key", auto_error=False)
    
    
    class User(BaseModel):
        username: str
    
    
    def get_current_user(oauth_header: Optional[str] = Security(api_key)):
        if oauth_header is None:
            return None
    Registered: Sun Oct 27 07:19:11 UTC 2024
    - Last Modified: Fri Jun 30 18:25:16 UTC 2023
    - 2K bytes
    - Viewed (0)
  4. docs/zh/docs/tutorial/dependencies/index.md

    ็„ถๅŽ๏ผŒไพ่ต–้กนๅ‡ฝๆ•ฐ่ฟ”ๅ›žๅŒ…ๅซ่ฟ™ไบ›ๅ€ผ็š„ `dict`ใ€‚
    
    ### ๅฏผๅ…ฅ `Depends`
    
    ```Python hl_lines="3"
    {!../../docs_src/dependencies/tutorial001.py!}
    ```
    
    ### ๅฃฐๆ˜Žไพ่ต–้กน
    
    ไธŽๅœจ*่ทฏๅพ„ๆ“ไฝœๅ‡ฝๆ•ฐ*ๅ‚ๆ•ฐไธญไฝฟ็”จ `Body`ใ€`Query` ็š„ๆ–นๅผ็›ธๅŒ๏ผŒๅฃฐๆ˜Žไพ่ต–้กน้œ€่ฆไฝฟ็”จ `Depends` ๅ’Œไธ€ไธชๆ–ฐ็š„ๅ‚ๆ•ฐ๏ผš
    
    ```Python hl_lines="15  20"
    {!../../docs_src/dependencies/tutorial001.py!}
    ```
    
    ่™ฝ็„ถ๏ผŒๅœจ่ทฏๅพ„ๆ“ไฝœๅ‡ฝๆ•ฐ็š„ๅ‚ๆ•ฐไธญไฝฟ็”จ `Depends` ็š„ๆ–นๅผไธŽ `Body`ใ€`Query` ็›ธๅŒ๏ผŒไฝ† `Depends` ็š„ๅทฅไฝœๆ–นๅผ็•ฅๆœ‰ไธๅŒใ€‚
    
    ่ฟ™้‡Œๅช่ƒฝไผ ็ป™ Depends ไธ€ไธชๅ‚ๆ•ฐใ€‚
    
    ไธ”่ฏฅๅ‚ๆ•ฐๅฟ…้กปๆ˜ฏๅฏ่ฐƒ็”จๅฏน่ฑก๏ผŒๆฏ”ๅฆ‚ๅ‡ฝๆ•ฐใ€‚
    
    Registered: Sun Oct 27 07:19:11 UTC 2024
    - Last Modified: Sun Oct 06 20:36:54 UTC 2024
    - 7K bytes
    - Viewed (0)
  5. docs/de/docs/tutorial/security/get-current-user.md

    ///
    
    ```Python hl_lines="19-22  26-27"
    {!> ../../docs_src/security/tutorial002.py!}
    ```
    
    ////
    
    ## Den aktuellen Benutzer einfรผgen
    
    Und jetzt kรถnnen wir wiederum `Depends` mit unserem `get_current_user` in der *Pfadoperation* verwenden:
    
    //// tab | Python 3.10+
    
    ```Python hl_lines="31"
    {!> ../../docs_src/security/tutorial002_an_py310.py!}
    ```
    
    ////
    
    Registered: Sun Oct 27 07:19:11 UTC 2024
    - Last Modified: Sun Oct 06 20:36:54 UTC 2024
    - 8.3K bytes
    - Viewed (0)
  6. docs/ko/docs/tutorial/security/get-current-user.md

    /// tip | "ํŒ"
    
    ์š”์ฒญ ๋ณธ๋ฌธ๋„ Pydantic ๋ชจ๋ธ๋กœ ์„ ์–ธ๋œ๋‹ค๋Š” ๊ฒƒ์„ ๊ธฐ์–ตํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.
    
    ์—ฌ๊ธฐ์„œ **FastAPI**๋Š” `Depends`๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํ˜ผ๋™๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
    
    ///
    
    /// check | "ํ™•์ธ"
    
    ์ด ์˜์กด์„ฑ ์‹œ์Šคํ…œ์ด ์„ค๊ณ„๋œ ๋ฐฉ์‹์€ ๋ชจ๋‘ `User` ๋ชจ๋ธ์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋‹ค์–‘ํ•œ ์˜์กด์„ฑ(๋‹ค๋ฅธ "์˜์กด์ ์ธ")์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.
    
    ํ•ด๋‹น ํƒ€์ž…์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ๋Š” ์˜์กด์„ฑ์ด ํ•˜๋‚˜๋งŒ ์žˆ๋Š” ๊ฒƒ์œผ๋กœ ์ œํ•œ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
    
    ///
    
    ## ๋‹ค๋ฅธ ๋ชจ๋ธ
    
    ์ด์ œ *๊ฒฝ๋กœ ์ž‘๋™ ํ•จ์ˆ˜*์—์„œ ํ˜„์žฌ ์‚ฌ์šฉ์ž๋ฅผ ์ง์ ‘ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์œผ๋ฉฐ `Depends`๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ **์˜์กด์„ฑ ์ฃผ์ž…** ์ˆ˜์ค€์—์„œ ๋ณด์•ˆ ๋ฉ”์ปค๋‹ˆ์ฆ˜์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    
    Registered: Sun Oct 27 07:19:11 UTC 2024
    - Last Modified: Sun Oct 06 20:36:54 UTC 2024
    - 5.6K bytes
    - Viewed (0)
  7. docs/em/docs/tutorial/security/get-current-user.md

    ๐Ÿ‘† 5๏ธโƒฃ๐Ÿ“† ๐Ÿ’ญ ๐Ÿ‘ˆ ๐Ÿ“จ ๐Ÿ’ช ๐Ÿ“ฃ โฎ๏ธ Pydantic ๐Ÿท.
    
    ๐Ÿ“ฅ **FastAPI** ๐Ÿ† ๐Ÿšซ ๐Ÿคš ๐Ÿ˜จ โ†ฉ๏ธ ๐Ÿ‘† โš™๏ธ `Depends`.
    
    ///
    
    /// check
    
    ๐ŸŒŒ ๐Ÿ‘‰ ๐Ÿ”— โš™๏ธ ๐Ÿ— โœ” ๐Ÿ‘ฅ โœ”๏ธ ๐ŸŽ ๐Ÿ”— (๐ŸŽ "โ˜‘") ๐Ÿ‘ˆ ๐ŸŒ ๐Ÿ“จ `User` ๐Ÿท.
    
    ๐Ÿ‘ฅ ๐Ÿšซ ๐Ÿšซ โœ”๏ธ ๐Ÿ•ด 1๏ธโƒฃ ๐Ÿ”— ๐Ÿ‘ˆ ๐Ÿ’ช ๐Ÿ“จ ๐Ÿ‘ˆ ๐Ÿ†Ž ๐Ÿ’ฝ.
    
    ///
    
    ## ๐ŸŽ ๐Ÿท
    
    ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ”œ ๐Ÿคš โฎ๏ธ ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ”— *โžก ๐Ÿ› ๏ธ ๐Ÿ”ข* & ๐Ÿ™… โฎ๏ธ ๐Ÿ’‚โ€โ™‚ ๐Ÿ› ๏ธ **๐Ÿ”— ๐Ÿ’‰** ๐ŸŽš, โš™๏ธ `Depends`.
    
    & ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ™† ๐Ÿท โš–๏ธ ๐Ÿ’ฝ ๐Ÿ’‚โ€โ™‚ ๐Ÿ“„ (๐Ÿ‘‰ ๐Ÿ’ผ, Pydantic ๐Ÿท `User`).
    
    Registered: Sun Oct 27 07:19:11 UTC 2024
    - Last Modified: Sun Oct 06 20:36:54 UTC 2024
    - 4.3K bytes
    - Viewed (0)
  8. tests/test_security_oauth2_optional.py

            return None
        user = User(username=oauth_header)
        return user
    
    
    @app.post("/login")
    def login(form_data: OAuth2PasswordRequestFormStrict = Depends()):
        return form_data
    
    
    @app.get("/users/me")
    def read_users_me(current_user: Optional[User] = Depends(get_current_user)):
        if current_user is None:
            return {"msg": "Create an account first"}
        return current_user
    
    
    client = TestClient(app)
    
    Registered: Sun Oct 27 07:19:11 UTC 2024
    - Last Modified: Thu Apr 18 19:40:57 UTC 2024
    - 10.8K bytes
    - Viewed (0)
  9. docs_src/websockets/tutorial002_an_py310.py

    from typing import Annotated
    
    from fastapi import (
        Cookie,
        Depends,
        FastAPI,
        Query,
        WebSocket,
        WebSocketException,
        status,
    )
    from fastapi.responses import HTMLResponse
    
    app = FastAPI()
    
    html = """
    <!DOCTYPE html>
    <html>
        <head>
            <title>Chat</title>
        </head>
        <body>
            <h1>WebSocket Chat</h1>
            <form action="" onsubmit="sendMessage(event)">
    Registered: Sun Oct 27 07:19:11 UTC 2024
    - Last Modified: Sat Mar 18 12:29:59 UTC 2023
    - 2.8K bytes
    - Viewed (0)
  10. docs_src/websockets/tutorial002_py310.py

    from fastapi import (
        Cookie,
        Depends,
        FastAPI,
        Query,
        WebSocket,
        WebSocketException,
        status,
    )
    from fastapi.responses import HTMLResponse
    
    app = FastAPI()
    
    html = """
    <!DOCTYPE html>
    <html>
        <head>
            <title>Chat</title>
        </head>
        <body>
            <h1>WebSocket Chat</h1>
            <form action="" onsubmit="sendMessage(event)">
    Registered: Sun Oct 27 07:19:11 UTC 2024
    - Last Modified: Sat Mar 18 12:29:59 UTC 2023
    - 2.7K bytes
    - Viewed (0)
Back to top