[FastAPI-06]路径转换器

from fastapi import FastAPI

app= FastAPI()

# 路径转换器
'''
- str 字符串
- int 数字
- float 浮点
- uuid 返回python中的uuid.UUID
- path 文件路径包含多个/
'''
@app.get("/books/{number:int}")
def books(number):
    print(type(number))
    return {"msg":{"BookNumber":number,"Price":20}}

# /opt/data/my.cnf
@app.get("/files/{path:path}")
def upload_files(path):
    return {"msg":{"file_path":path}}
posted @ 2023-03-23 10:14  LeoShi2020  阅读(48)  评论(0)    收藏  举报