【发布时间】:2022-08-18 20:53:12
【问题描述】:
我有一个用于随机茶照片的 API,但希望它以 JSON 格式返回照片作为不和谐机器人和事物的 URL。这是我到目前为止所拥有的:
def getRandomFile(path):
\"\"\"
Returns a random filename, chosen among the files of the given path.
\"\"\"
files = os.listdir(path)
index = random.randrange(0, len(files))
return files[index]
@app.get(\"/\")
async def home():
return RedirectResponse(\"/docs\")
@app.get(\"/tea\")
def tea():
x = \"teacuppics/{}\".format(getRandomFile(\"teacuppics\"))
return FileResponse(x)
如何将图像的回复交换为 JSON 回复?
标签: python json python-3.x fastapi