from contextlib import asynccontextmanager from fastapi import FastAPI, Request, Depends from fastapi.templating import Jinja2Templates from database import create_db_and_tables, get_session, ShoppingItem from sqlmodel import Session # Wird beim Starten des Servers exakt einmal ausgeführt @asynccontextmanager async def lifespan(app: FastAPI): create_db_and_tables() yield app = FastAPI(lifespan=lifespan) templates = Jinja2Templates(directory="templates") @app.get("/") async def home(request: Request, session: Session = Depends(get_session)): # Hier können wir bald Daten aus der DB laden return templates.TemplateResponse(request=request, name="index.html")