https://www.bilibili.com/video/BV1Fi4y1w7iv/?spm_id_from=333.337.search-card.all.click&vd_source=aa5c2b5a49df287e56cb7d40832d79cb
pip install fastapi[all]
pip install uvicorn
启动项目
uvicorn main:app --reload
main.py
标签:username,return,app,笔记,phone,user,message From: https://www.cnblogs.com/eric-share/p/18666916
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
@app.get("/")
async def index ():
return {
"code":200,
"data":[
'eric','jack'
],
"message": "success"
}
class LoginUser(BaseModel):
phone: str
code: str
class UsernameAndPassword(BaseModel):
username: str
password: str
is_save: bool = False
@app.post("/login")
def user_login_by_phone(user: LoginUser):
return {"message": "登录成功",'phone': user.phone}
@app.post("/login2")
def user_login_by_username(user: UsernameAndPassword):
return {"message": "用户登录失败",'username': user.username}