Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

90
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda