Skip to content

Instantly share code, notes, and snippets.

Last active January 19, 2022 20:15
What would you like to do?
Stackoverflow Example
from fastapi import FastAPI, APIRouter, Request
from fastapi.responses import RedirectResponse, HTMLResponse
router = APIRouter()
def form():
return HTMLResponse("""
<form action="/event/create" method="POST">
<button>Send request</button>
async def event_create(
request: Request
event = {"id": 123}
redirect_url = request.url_for('get_event', **{'pk': event['id']})
return RedirectResponse(redirect_url, status_code=303)
async def get_event(
request: Request,
pk: int,
return f'<html>oi pk={pk}</html>'
app = FastAPI(title='Test API')
app.include_router(router, prefix="/event")
# run:
# uvicorn --reload --host --port 3000 example:app
# then point your browser to: http://localhost:3000/event/form
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment