# server_simple.py - упрощенная версия без Jinja2 import re import json from datetime import datetime from pathlib import Path from fastapi import FastAPI, Form from fastapi.responses import HTMLResponse, JSONResponse from fastapi.staticfiles import StaticFiles # ==================== КОНФИГУРАЦИЯ ==================== HOST = "0.0.0.0" PORT = 8000 BASE_DIR = Path(__file__).parent STATIC_DIR = BASE_DIR / "static" DATA_DIR = BASE_DIR / "data" STATIC_DIR.mkdir(exist_ok=True) DATA_DIR.mkdir(exist_ok=True) (STATIC_DIR / "css").mkdir(exist_ok=True) (STATIC_DIR / "js").mkdir(exist_ok=True) app = FastAPI() app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static") # Читаем HTML файл HTML_FILE = BASE_DIR / "templates" / "index.html" def save_registration_to_file(data: dict) -> dict: filepath = DATA_DIR / "registrations.json" registrations = [] if filepath.exists(): try: with open(filepath, 'r', encoding='utf-8') as f: registrations = json.load(f) except: registrations = [] new_record = { "id": len(registrations) + 1, "created_at": datetime.now().isoformat(), **data, "status": "pending" } registrations.append(new_record) with open(filepath, 'w', encoding='utf-8') as f: json.dump(registrations, f, ensure_ascii=False, indent=2) return new_record @app.get("/", response_class=HTMLResponse) async def get_landing_page(): if HTML_FILE.exists(): with open(HTML_FILE, 'r', encoding='utf-8') as f: return HTMLResponse(content=f.read()) else: return HTMLResponse(content="
| {r.get('fullname')} | {r.get('email')} |