Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

239
Vistas
FastAPI equivalent of Flask's request.form, for agnostic forms

I try to migrate from Flask to FastAPI, and I was wondering if there is something similar to Flask's:

payload = request.form.to_dict(flat=False)
payload = {key:payload[key][0] for key in payload}

for FastAPI.

Until now I've found only some hacks, were you still had to implement one-by-one all the form's arguments to a function:

from pydantic import BaseModel
class FormData(BaseModel):
    alfa: str=Form(...)
    vita: str=Form(...)
async def Home(request: Request, form_data:FormData)

This example is of course better in readability than the standard form handling:

async def Home(username: str = Form(...), something_else: str = Form(...)):

But still it's quite restricting, due to the necessary declaration of all form fields.

Is there any other more agnostic & elegant approach?

Thanks in advance & I apologize if this a trivial question I've failed to find through googling :)

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can get the underlying starlette request and use its request.form() method. It requires python-multipart to work:

from fastapi import FastAPI, Request

app = FastAPI()

@app.post("/example")
async def example(request: Request):
    form_data = await request.form()
    return form_data

Example of calling it:

C:\>curl -X POST "http://localhost:8000/example" -d "hello=there&another=value"
{"hello":"there","another":"value"}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda