コンテンツにスキップ
per page, with , order by , clip by
Results of 1 - 1 of about 1 for CommonQueryParams (0.001 sec.)
依存関係としてのクラス 9414
依存関係としてのクラス 依存性注入 システムを深く掘り下げる前に、先ほどの例をアップグレードしてみましょう。 前の例の dict 前の例では、依存関係("dependable")から dict を返していました: Python 3.8+ - non-Annotated from typing import Union fr ... ものにも適用されます。パラメータのない path operation関数 と同じように。 そこで、上で紹介した依存関係の common_parameters を CommonQueryParams クラスに変更します: Python 3.8+ - non-Annotated from typing import Union from fastapi import Depends , FastAPI app = FastA ... PI () fake_items_db = [{ "item_name" : "Foo" }, { "item_name" : "Bar" }, { "item_name" : "Baz" }] class CommonQueryParams : def __init__ ( self , q : Union [ str , None ] = None , skip : int = 0 , limit : int = 100 ): self . q = q self . skip = ... skip self . limit = limit @app . get ( "/items/" ) async def read_items ( commons : CommonQueryParams = Depends ( CommonQueryParams )): response = {} if commons . q : response . update ({ "q" : commons . q }) items = fake_it ...
https://man.mtool.work/fastapi/0.115/tutorial/dependencies/classes-as-dependenci...
PREV 1 NEXT