pip install python-multipart
# coding: utf8
from fastapi import FastAPI, Form
app = FastAPI()
@app.post('/login')
async def login(
username: str=Form(..., max_length=16, min_length=6, regex='[a-zA-Z0-9]'),
password: str=Form(..., max_length=16, min_length=6, regex='[a-zA-Z0-9]')
):
return {'username': username, 'password': password}
# # 启动: uvicorn main:app --reload
curl --location --request POST 'http://10.11.9.247:8000/login' \
--form 'username="superadmin"' \
--form 'password="superadmin"'
{
"username": "superadmin",
"password": "superadmin"
}