mirror of
https://github.com/fastapi/fastapi.git
synced 2026-05-18 13:27:45 -04:00
✨ Allow setting the response_class to RedirectResponse and returning the URL from the function (#3457)
This commit is contained in:
committed by
GitHub
parent
ea8d7f689e
commit
dc5a966548
@@ -5,5 +5,5 @@ app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/typer")
|
||||
async def read_typer():
|
||||
async def redirect_typer():
|
||||
return RedirectResponse("https://typer.tiangolo.com")
|
||||
|
||||
9
docs_src/custom_response/tutorial006b.py
Normal file
9
docs_src/custom_response/tutorial006b.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import RedirectResponse
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/fastapi", response_class=RedirectResponse)
|
||||
async def redirect_fastapi():
|
||||
return "https://fastapi.tiangolo.com"
|
||||
9
docs_src/custom_response/tutorial006c.py
Normal file
9
docs_src/custom_response/tutorial006c.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import RedirectResponse
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/pydantic", response_class=RedirectResponse, status_code=302)
|
||||
async def redirect_pydantic():
|
||||
return "https://pydantic-docs.helpmanual.io/"
|
||||
10
docs_src/custom_response/tutorial009b.py
Normal file
10
docs_src/custom_response/tutorial009b.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import FileResponse
|
||||
|
||||
some_file_path = "large-video-file.mp4"
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/", response_class=FileResponse)
|
||||
async def main():
|
||||
return some_file_path
|
||||
Reference in New Issue
Block a user