Skip to content

Commit

Permalink
Create Landing page
Browse files Browse the repository at this point in the history
  • Loading branch information
Zingzy committed Jan 20, 2024
1 parent d64d7d2 commit 808de50
Show file tree
Hide file tree
Showing 2 changed files with 392 additions and 0 deletions.
12 changes: 12 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
StreamingResponse,
RedirectResponse,
)
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles
from cachetools import TTLCache
import random
from io import BytesIO
import os
import uvicorn


app = FastAPI(title="Panda API", description="An API for pandas", version="0.0.1")
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")

# Enable CORS
origins = ["*"]
Expand Down Expand Up @@ -41,6 +46,13 @@ def create_cache():
cache = Depends(create_cache)


@app.get("/")
async def read_root(request: Request):
base_url = str(request.base_url)
base_url_no_http = base_url[base_url.find("//")+2:-1]
return templates.TemplateResponse("index.html", {"request": request, "base_url": request.base_url, "base_url_no_http": base_url_no_http})


@app.get("/fact", tags=["facts"])
def get_random_fact():
return JSONResponse(content={"fact": random.choice(panda_facts)})
Expand Down
Loading

0 comments on commit 808de50

Please sign in to comment.