作者:麥克煎蛋 出處:https://www.cnblogs.com/mazhiyong/ 轉載請保留這段聲明,謝謝!
我們可以用Form組件來接收表單數據。
1、安裝組件
pip install python-multipart
2、導入組件
from fastapi import Form
3、表單參數
聲明表單參數的方式與Query或者Path相同。
Form的詳細使用可參考Query、Path、Cookie、Body。它直接繼承自Body。
from fastapi import FastAPI, Form app = FastAPI() @app.post("/login/") async def login(*, username: str = Form(...), password: str = Form(...)):
return {"username": username}
訪問示例: