コンテンツにスキップ
per page, with , order by , clip by
Results of 1 - 10 of about 31 for dict (0.010 sec.)
Simple OAuth2 with Password and Bearer 12537
Simple OAuth2 with Password and Bearer Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Now let's build from the previous chapter and add the missing parts to have ... None = None class UserInDB ( User ): hashed_password : str def get_user ( db , username : str ): if username in db : user_dict = db [ username ] return UserInDB ( ** user_dict ) def fake_decode_token ( token ): # This doesn't provide any security at ... ent_user @app . post ( "/token" ) async def login ( form_data : Annotated [ OAuth2PasswordRequestForm , Depends ()]): user_dict = fake_users_db . get ( form_data . username ) if not user_dict : raise HTTPException ( status_code = 400 , detail = "Inco ... rrect username or password" ) user = UserInDB ( ** user_dict ) hashed_password = fake_hash_password ( form_data . password ) if not hashed_password == user . hashed_password : raise H ...
https://man.mtool.work/fastapi/0.115/tutorial/security/simple-oauth2/
モデル - より詳しく 11987
モデル - より詳しく 先ほどの例に続き、複数の関連モデルを持つことが一般的です。 これはユーザーモデルの場合は特にそうです。なぜなら: 入力モデル にはパスワードが必要です。 出力モデル はパスワードをもつべきではありません。 データベースモデル は ... r ( user_in : UserIn ): hashed_password = fake_password_hasher ( user_in . password ) user_in_db = UserInDB ( ** user_in . dict (), hashed_password = hashed_password ) print ( "User saved! ..not really" ) return user_in_db @app . post ( "/user/" , re ... r ( user_in : UserIn ): hashed_password = fake_password_hasher ( user_in . password ) user_in_db = UserInDB ( ** user_in . dict (), hashed_password = hashed_password ) print ( "User saved! ..not really" ) return user_in_db @app . post ( "/user/" , re ... UserOut ) async def create_user ( user_in : UserIn ): user_saved = fake_save_user ( user_in ) return user_saved **user_in.dict() について Pydanticの .dict() user_in は UserIn クラスのPydanticモデルです。 Pydanticモデルには、モデルのデータを含む dict ...
https://man.mtool.work/fastapi/0.115/tutorial/extra-models/
OAuth2 scopes 10903
OAuth2 scopes Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can use OAuth2 scopes directly with FastAPI , they are integrated to work seamlessly. This would ... d_hash ( password ): return pwd_context . hash ( password ) def get_user ( db , username : str ): if username in db : user_dict = db [ username ] return UserInDB ( ** user_dict ) def authenticate_user ( fake_db , username : str , password : str ): us ... se if not verify_password ( password , user . hashed_password ): return False return user def create_access_token ( data : dict , expires_delta : timedelta | None = None ): to_encode = data . copy () if expires_delta : expire = datetime . now ( timez ... d_hash ( password ): return pwd_context . hash ( password ) def get_user ( db , username : str ): if username in db : user_dict = db [ username ] return UserInDB ( ** user_dict ) def authenticate_user ( fake_db , username : str , password : str ): us ...
https://man.mtool.work/fastapi/0.115/advanced/security/oauth2-scopes/
依存関係 - 最初のステップ 10790
依存関係 - 最初のステップ ** FastAPI** は非常に強力でありながら直感的な 依存性注入 システムを持っています。 それは非常にシンプルに使用できるように設計されており、開発者が他のコンポーネント FastAPI と統合するのが非常に簡単になるように設計され ... nt = 100 ): return { "q" : q , "skip" : skip , "limit" : limit } @app . get ( "/items/" ) async def read_items ( commons : dict = Depends ( common_parameters )): return commons @app . get ( "/users/" ) async def read_users ( commons : dict = Depends ... return { "q" : q , "skip" : skip , "limit" : limit } @app . get ( "/items/" ) async def read_items ( commons : Annotated [ dict , Depends ( common_parameters )]): return commons @app . get ( "/users/" ) async def read_users ( commons : Annotated [ di ... return { "q" : q , "skip" : skip , "limit" : limit } @app . get ( "/items/" ) async def read_items ( commons : Annotated [ dict , Depends ( common_parameters )]): return commons @app . get ( "/users/" ) async def read_users ( commons : Annotated [ di ...
https://man.mtool.work/fastapi/0.115/tutorial/dependencies/
パスワード(およびハッシュ化)によるOAuth2、JWTトークンによるBearer 10272
パスワード(およびハッシュ化)によるOAuth2、JWTトークンによるBearer これでセキュリティの流れが全てわかったので、 JWT トークンと安全なパスワードのハッシュ化を使用して、実際にアプリケーションを安全にしてみましょう。 このコードは、アプリケーシ ... d_hash ( password ): return pwd_context . hash ( password ) def get_user ( db , username : str ): if username in db : user_dict = db [ username ] return UserInDB ( ** user_dict ) def authenticate_user ( fake_db , username : str , password : str ): us ... se if not verify_password ( password , user . hashed_password ): return False return user def create_access_token ( data : dict , expires_delta : Union [ timedelta , None ] = None ): to_encode = data . copy () if expires_delta : expire = datetime . n ... d_hash ( password ): return pwd_context . hash ( password ) def get_user ( db , username : str ): if username in db : user_dict = db [ username ] return UserInDB ( ** user_dict ) def authenticate_user ( fake_db , username : str , password : str ): us ...
https://man.mtool.work/fastapi/0.115/tutorial/security/oauth2-jwt/
依存関係としてのクラス 9156
依存関係としてのクラス 依存性注入 システムを深く掘り下げる前に、先ほどの例をアップグレードしてみましょう。 前の例の dict 前の例では、依存関係("dependable")から dict を返していました: Python 3.8+ - non-Annotated from typing import Union fr ... nt = 100 ): return { "q" : q , "skip" : skip , "limit" : limit } @app . get ( "/items/" ) async def read_items ( commons : dict = Depends ( common_parameters )): return commons @app . get ( "/users/" ) async def read_users ( commons : dict = Depends ... return { "q" : q , "skip" : skip , "limit" : limit } @app . get ( "/items/" ) async def read_items ( commons : Annotated [ dict , Depends ( common_parameters )]): return commons @app . get ( "/users/" ) async def read_users ( commons : Annotated [ di ... return { "q" : q , "skip" : skip , "limit" : limit } @app . get ( "/items/" ) async def read_items ( commons : Annotated [ dict , Depends ( common_parameters )]): return commons @app . get ( "/users/" ) async def read_users ( commons : Annotated [ di ...
https://man.mtool.work/fastapi/0.115/tutorial/dependencies/classes-as-dependenci...
リクエストボディ 8929
リクエストボディ クライアント (ブラウザなど) からAPIにデータを送信する必要があるとき、データを リクエストボディ (request body) として送ります。 リクエスト ボディはクライアントによってAPIへ送られます。 レスポンス ボディはAPIがクライアントに送 ... ョナルな属性にしたい場合は None を使用してください。 例えば、上記のモデルは以下の様なJSON「 オブジェクト 」(もしくはPythonの dict ) を宣言しています: { "name" : "Foo" , "description" : "An optional description" , "price" : 45.2 , "tax" : 3.5 } ... desc ... キュメントにも表示されます: エディターサポート エディターによる型ヒントと補完が関数内で利用できます (Pydanticモデルではなく dict を受け取ると、同じサポートは受けられません): 型によるエラーチェックも可能です: これは偶然ではなく、このデザインに基づいてフ ... tax : Union [ float , None ] = None app = FastAPI () @app . post ( "/items/" ) async def create_item ( item : Item ): item_dict = item . dict () if item . tax is not None : price_with_tax = item . price + item . tax item_dict . update ({ "price_with_ ...
https://man.mtool.work/fastapi/0.115/tutorial/body/
Additional Responses in OpenAPI 8784
Additional Responses in OpenAPI Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Warning This is a rather advanced topic. If you are starting with FastAPI , you mig ... ntent. Additional Response with model You can pass to your path operation decorators a parameter responses . It receives a dict : the keys are status codes for each response (like 200 ), and the values are other dict s with the information for each o ... f them. Each of those response dict s can have a key model , containing a Pydantic model, just like response_model . FastAPI will take that model, generate it ... chema, and put it in the correct place. The correct place is: In the key content , that has as value another JSON object ( dict ) that contains: A key with the media type, e.g. application/json , that contains as value another JSON object, that conta ...
https://man.mtool.work/fastapi/0.115/advanced/additional-responses/
Testing Dependencies with Overrides 8752
Testing Dependencies with Overrides Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Overriding dependencies during testing There are some scenarios where you might ... y_overrides attribute For these cases, your FastAPI application has an attribute app.dependency_overrides , it is a simple dict . To override a dependency for testing, you put as a key the original dependency (a function), and as the value, your depe ... return { "q" : q , "skip" : skip , "limit" : limit } @app . get ( "/items/" ) async def read_items ( commons : Annotated [ dict , Depends ( common_parameters )]): return { "message" : "Hello Items!" , "params" : commons } @app . get ( "/users/" ) asy ... nc def read_users ( commons : Annotated [ dict , Depends ( common_parameters )]): return { "message" : "Hello Users!" , "params" : commons } client = TestClient ( app ) ...
https://man.mtool.work/fastapi/0.115/advanced/testing-dependencies/
ボディ - 更新 8671
ボディ - 更新 PUT による置換での更新 項目を更新するには HTTPの PUT 操作を使用することができます。 jsonable_encoder を用いて、入力データをJSON形式で保存できるデータに変換することができます(例:NoSQLデータベース)。例えば、 datetime を str に ... 多かれ少なかれ、示しています。 Pydanticの exclude_unset パラメータの使用 部分的な更新を受け取りたい場合は、Pydanticモデルの .dict() の exclude_unset パラメータを使用すると非常に便利です。 item.dict(exclude_unset=True) のように。 これにより、 item モデル ... の作成時に設定されたデータのみを持つ dict が生成され、デフォルト値は除外されます。 これを使うことで、デフォルト値を省略して、設定された(リクエストで送られた)データ ... のみを含む dict を生成することができます: Python 3.8+ from typing import List , Union from fastapi import FastAPI from fastapi.encoders im ...
https://man.mtool.work/fastapi/0.115/tutorial/body-updates/
PREV 1 2 3 4 NEXT