Last active
December 30, 2021 19:20
-
-
Save kaustubhgupta/53d91e4d710173ce264358c90de4a906 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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