This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RedirectResponse from a POST request route to GET request route shows 405 Error code. #1498
Comments
https://developer.mozilla.org/docs/Web/HTTP/Status/307 To override the status code, pass parameter |
Are you suggesting below snippet like this?: Well this doesn't really solve the problem, same error: |
If no one has already I'd like to give this a go :) |
Thanks for the help here @phy25 and for the other @gmelodie ! 🚀 I actually can't reproduce it... 🤔 Here's a small app that seems to be working: from fastapi import FastAPI, status
from fastapi.responses import RedirectResponse
app = FastAPI()
@app.post("/")
async def login():
return RedirectResponse(url="/ressource/1", status_code=status.HTTP_303_SEE_OTHER)
@app.get("/ressource/{r_id}")
async def get_ressource(r_id: str):
return {"r_id": r_id} When using the docs UI, open the browser developer tools, in the "Network" tab, to see the redirection underneath: You can see that after the |
It's working. Thanks a lot.@tiangolo |
WOW !!! Thanks alot !!! Was facing with the same issue. Resolved Now :) |
How to redirect from GET to POST i used the above there but got 405 error. please help |
@Suman2023 You most likely have to enable CORS |
@tiangolo great solution faced the same issue and resolved, but can you please elaborate why it wasnt working without explicit status code. |
The RedirectResponse by default uses HTTP 307 - Temporary Redirect. The documentation for that says
The browser will do all the work for you to redirect, based on the status code. 303 See Other will redirect to another URL, using a GET request. I assume it will not work for redirecting to a POST, PUT or DELETE endpoint |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Summary of the total issue is: How to do a Post/Redirect/Get (PRG) in FastAPI?
This is not necessarily a bug, rather a question.
Things i tried:
I want to redirect response from 2nd route to 1st route. This Issue#199 here explains GET to GET but not a POST to GET. N.B:
I have done this type of POST -> GET redirecting in flask, it was working there but not here.
And also this Issue#863 has the same problem but doesn't really solves the problem. To re produce the error check the bottom.But it shows :
Full traceback:
But when i do a GET to GET redirect response it works without any issue but a POST to GET blows things up! Am i completely missing something here? i did look up in starlette doc here on reverse route lookup but nothing helps. https://www.starlette.io/routing/#reverse-url-lookups
Quick Re produce the error:
The text was updated successfully, but these errors were encountered: