krll/main.py

44 lines
1,015 B
Python
Raw Normal View History

from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
2024-02-19 12:21:12 +09:00
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware
from fastapi.templating import Jinja2Templates
2024-02-19 12:21:12 +09:00
from src.database import engine
from src import models
from src.routes.url import url_route
models.Base.metadata.create_all(bind=engine)
app = FastAPI()
templates = Jinja2Templates(directory="templates")
2024-02-19 12:21:12 +09:00
origins = [
"*",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.mount("/static", StaticFiles(directory="./static"), name="static")
@app.get("/", response_class=HTMLResponse)
def index(request: Request):
return templates.TemplateResponse(request=request, name="index.html")
2024-02-19 12:21:12 +09:00
@app.get("/about", response_class=HTMLResponse)
def about(request: Request):
return templates.TemplateResponse(request=request, name="about.html")
app.include_router(url_route.routes)