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

91
Vistas
Serving directories with FastAPI application

I need to serve a directory that contains data, like how Apache serves an index, and I would like to serve it through my FastAPI application.

Is that possible with FastAPI or Starlette?

If not, Simplehttpserver alternatives suggests Twistd as a python package. Is it possible to have FastAPI redirect to a twistd server at the directory mount?

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

0

You're looking for the StaticFiles utility:

from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles

app = FastAPI()

app.mount("/", StaticFiles(directory="static"), name="static")

Arguments usage is documented on FastAPI documentation:

  • The first "/" refers to the path this "sub-application" will be "mounted" on. Kn this case, all paths will be handled by it.

  • The directory="static" refers to the name of the directory that contains your static files on your local filesystem.

  • The name="static" gives it a name that can be used internally by FastAPI.

All these parameters can be different than "static", adjust them with the needs and specific details of your own application.

Note: You will need to install aiofiles: pip install aiofiles

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