[FastAPI-02]动态静态路由

from fastapi import FastAPI

app= FastAPI()

# 静态路由模式
@app.get("/login")
def login():
    return {"msg":"Welcome CoCo Login"}

@app.get("/books/{number}")
# number:int 类型必须为int 否则会报错
def books(number:int):
    return {"msg":{"BookNumber":number,"Price":20}}

http://10.105.212.1:8000/books/100

{
  "msg": {
    "BookNumber": 100,
    "Price": 20
  }
}
posted @ 2023-03-21 16:29  LeoShi2020  阅读(35)  评论(0编辑  收藏  举报