From 59fc7a0a5b28068002f62749502f7eaa1871c055 Mon Sep 17 00:00:00 2001 From: Stas Medvedev Date: Tue, 11 Jun 2024 00:43:21 +0300 Subject: =?UTF-8?q?=D0=9D=D0=B0=D0=BA=D0=B8=D0=B4=D0=B0=D0=BB=20html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/main.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/main.py b/app/main.py index d9ea01c..891adb1 100644 --- a/app/main.py +++ b/app/main.py @@ -1,11 +1,27 @@ +from pathlib import Path + from fastapi import FastAPI, Request from fastapi.responses import HTMLResponse +from fastapi.staticfiles import StaticFiles from starlette.templating import Jinja2Templates import httpx +templates = Jinja2Templates(directory="templates") + app = FastAPI() +app.mount("/static", StaticFiles(directory="static"), name="static") -templates = Jinja2Templates(directory="templates") + +def get_avatar_urls(): + path = Path('./static') / 'avatars' + if not path.exists(): + path.mkdir() + + return sorted([ + str(jpg_avatar) + for jpg_avatar + in path.glob('*.jpg') + ]) def get_client_host(request: Request): @@ -31,6 +47,7 @@ async def index(request: Request): "request": request, "client_geo": await get_client_geo( get_client_host(request) - ) + ), + "avatar_urls": get_avatar_urls() } ) -- cgit v1.2.3