Skip to content

Instantly share code, notes, and snippets.

@kaustubhgupta
Last active December 30, 2021 19:20
Show Gist options
  • Save kaustubhgupta/53d91e4d710173ce264358c90de4a906 to your computer and use it in GitHub Desktop.
Save kaustubhgupta/53d91e4d710173ce264358c90de4a906 to your computer and use it in GitHub Desktop.
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles
from fastapi.responses import HTMLResponse
import uvicorn
app = FastAPI()
staticfiles = StaticFiles(directory="demo/toServe")
app.mount("/static", staticfiles, name="static")
templates = Jinja2Templates(directory="demo")
@app.get('/', response_class=HTMLResponse)
def index(request: Request):
return templates.TemplateResponse("demo.html", {"request": request, "title": "Kaustubh Demo", "body_content": "This is the demo for using FastAPI with Jinja templates"})
if __name__ == "__main__":
uvicorn.run("demo3:app", host='127.0.0.1', port=8000, reload=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment