from fastapi import FastAPI, Request, Form from fastapi.templating import Jinja2Templates from fastapi.staticfiles import StaticFiles from fastapi.responses import HTMLResponse, RedirectResponse from datetime import datetime
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static") templates = Jinja2Templates(directory="app/templates")
@app.middleware("http") async def add_global_context(request: Request, call_next): response = await call_next(request) return response
templates.env.globals["current_year"] = datetime.now().year
FEATURES = [ { "title": "Lightning Fast", "description": "One of the fastest Python frameworks available, on par with NodeJS and Go.", "icon": "M13 10V3L4 14h7v7l9-11h-7z" }, { "title": "Easy to Learn", "description": "Intuitive design with excellent documentation and IDE support.", "icon": "M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253" }, { "title": "Production Ready", "description": "Built-in validation, serialization, and automatic API documentation.", "icon": "M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z" } ]
PROJECTS = [ { "title": "E-Commerce Platform", "description": "A full-featured online store with cart, checkout, and payment integration.", "image": "https://images.unsplash.com/photo-1556742049-0cfed4f6a45d?w=800", "link": "/projects/ecommerce", "tags": ["FastAPI", "React", "Stripe"] }, { "title": "Task Management", "description": "Collaborative task tracking with real-time updates and team features.", "image": "https://images.unsplash.com/photo-1484480974693-6ca0a78fb36b?w=800", "link": "/projects/tasks", "tags": ["FastAPI", "WebSockets", "Vue"] }, { "title": "Analytics Dashboard", "description": "Real-time data visualization and reporting for business intelligence.", "image": "https://images.unsplash.com/photo-1551288049-bebda4e38f71?w=800", "link": "/projects/analytics", "tags": ["FastAPI", "Charts", "PostgreSQL"] } ]
STACK = [ {"name": "FastAPI", "emoji": "⚡", "description": "High-performance Python web framework"}, {"name": "Jinja2", "emoji": "📄", "description": "Powerful templating engine"}, {"name": "Tailwind CSS", "emoji": "🎨", "description": "Utility-first CSS framework"}, {"name": "PostgreSQL", "emoji": "🐘", "description": "Robust relational database"}, ]
@app.get("/", response_class=HTMLResponse) async def home(request: Request): return templates.TemplateResponse( "index.html", { "request": request, "title": "Home", "features": FEATURES, "projects": PROJECTS } )
@app.get("/about", response_class=HTMLResponse) async def about(request: Request): return templates.TemplateResponse( "about.html", { "request": request, "title": "About", "stack": STACK } )
@app.get("/contact", response_class=HTMLResponse) async def contact_form(request: Request): return templates.TemplateResponse( "contact.html", {"request": request, "title": "Contact"} )
@app.post("/contact") async def contact_submit( request: Request, name: str = Form(...), email: str = Form(...), message: str = Form(...) ): print(f"Contact from {name} ({email}): {message}")
return RedirectResponse(url="/contact?success=true", status_code=303)
|