我正在尝试从 POST 重定向到 GET。如何在 FastAPI 中实现这一点?
你尝试了什么?
我已经按照问题#863#FastAPI 的建议尝试了以下 HTTP_302_FOUND、HTTP_303_SEE_OTHER:但没有任何效果!
它总是显示 INFO: "GET / HTTP/1.1" 405 Method Not Allowed
from fastapi import FastAPI
from starlette.responses import RedirectResponse
import os
from starlette.status import HTTP_302_FOUND,HTTP_303_SEE_OTHER
app = FastAPI()
@app.post("/")
async def login():
# HTTP_302_FOUND,HTTP_303_SEE_OTHER : None is working:(
return RedirectResponse(url="/ressource/1",status_code=HTTP_303_SEE_OTHER)
@app.get("/ressource/{r_id}")
async def get_ressource(r_id:str):
return {"r_id": r_id}
# tes is the filename(tes.py) and app is the FastAPI instance
if __name__ == '__main__':
os.system("uvicorn tes:app --host 0.0.0.0 --port 80") …Run Code Online (Sandbox Code Playgroud)