Created
March 18, 2022 15:36
-
-
Save AD0791/7dd3117b56b49087604da0a929a09998 to your computer and use it in GitHub Desktop.
advanced_fastapi
This file contains hidden or 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 | |
apiv1 = FastAPI() | |
@apiv1.get('/returnName') | |
def index(): | |
return {"Name": "Kaustubh demo"} | |
################# | |
from fastapi import FastAPI | |
apiv2 = FastAPI() | |
@apiv2.get('/returnLocation') | |
def index(): | |
return {"Location": "India"} | |
######## | |
from fastapi import FastAPI | |
from apiv1 import apiv1 | |
from apiv2 import apiv2 | |
import uvicorn | |
app = FastAPI() | |
app.mount("/api/v1", apiv1) | |
app.mount("/api/v2", apiv2) | |
@app.get('/') | |
def index(): | |
return "Hello" | |
if __name__ == "__main__": | |
uvicorn.run("master:app", host='127.0.0.1', port=8000, reload=True) | |
This file contains hidden or 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 dash import html | |
from dash import dcc | |
import dash_bootstrap_components as dbc | |
import dash | |
dash_app = dash.Dash(__name__, | |
requests_pathname_prefix='/dashboard/', title='Kaustubh Demo') | |
header = dbc.Row( | |
dbc.Col( | |
[ | |
html.Div(style={"height": 30}), | |
html.H1("Demo", className="text-center"), | |
] | |
), | |
className="mb-4", | |
) | |
dash_app.layout = dbc.Container( | |
[ | |
header, | |
], | |
fluid=True, | |
className="bg-light", | |
) | |
################## | |
from fastapi import FastAPI | |
from fastapi.middleware.wsgi import WSGIMiddleware | |
from demo_dash import dash_app | |
import uvicorn | |
app = FastAPI() | |
app.mount("/dashboard", WSGIMiddleware(dash_app.server)) | |
@app.get('/') | |
def index(): | |
return "Hello" | |
if __name__ == "__main__": | |
uvicorn.run("main:app", host='127.0.0.1', port=8000, reload=True) | |
This file contains hidden or 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) | |
######### | |
<!doctype html> | |
<html lang="en"> | |
<head> | |
<title>{{title}}</title> | |
</head> | |
<body> | |
{{body_content}} | |
<img src="/static/img1.png"> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment