3
1

More than 1 year has passed since last update.

Python: FastAPI: @app.middleware("http") を複数書くとどうなる?

Posted at
...
@app.middleware("http")
async def f1(req: Request, call_next):
    print(f"⭐️{sys._getframe().f_code.co_name}")
    return await call_next(req)

@app.middleware("http")
async def f2(req: Request, call_next):
    print(f"⭐️{sys._getframe().f_code.co_name}")
    return await call_next(req)

@app.middleware("http")
async def f3(req: Request, call_next):
    print(f"⭐️{sys._getframe().f_code.co_name}")
    return await call_next(req)
...

⭐️f3
⭐️f2
⭐️f1

逆順にコールされた。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1