【FastAPI】From 表单使用

From 表单

需要安装 pip install python-multipart

From 有 Body (及 QueryPathCookie相同的元数据和验证。

from fastapi import FastAPI, Form
import uvicorn

app = FastAPI()

@app.post('/login')
async def login(user_name: str = Form(...), password: str = Form(...)):
    return {'user_name': user_name, 'password': password}

if __name__ == '__main__':
    uvicorn.run(app)

mark

发表评论 / Comment

用心评论~