In my project folder I have a basic index.html
file plus static files (js, css) as well as my main.py
:
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from fastapi import Request
app = FastAPI()
templates = Jinja2Templates(directory="/")
app.mount("/", StaticFiles(directory="/"))
@app.get("/")
def serve_home(request: Request):
return templates.TemplateResponse("index.html", context= {"request": request})
How can I make fastapi work here? I just want my index.html
and static files served on localhost.
Is it problematic not to have a static
or templates
folder?