updating web-dev
This commit is contained in:
@@ -1,31 +1,38 @@
|
||||
from starlette.applications import Starlette
|
||||
from starlette.templating import Jinja2Templates
|
||||
from starlette.routing import Route, Mount
|
||||
from starlette.staticfiles import StaticFiles
|
||||
from fastapi import FastAPI, Header, Path
|
||||
from pydantic import BaseModel
|
||||
from typing import List
|
||||
|
||||
|
||||
templates = Jinja2Templates(directory='templates')
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
async def home(request):
|
||||
return templates.TemplateResponse(
|
||||
'index.html',
|
||||
{'request': request},
|
||||
)
|
||||
class MetricResponse(BaseModel):
|
||||
data: List = [1, 2, 3]
|
||||
metrics: str
|
||||
|
||||
routes = [
|
||||
Route('/', endpoint=home),
|
||||
Mount('/static', StaticFiles(directory='../static'), name='static'),
|
||||
Mount(
|
||||
'/node_modules',
|
||||
StaticFiles(directory='../node_modules'),
|
||||
name='node_modules',
|
||||
|
||||
@app.get("/metrics/{metric}", response_model=MetricResponse)
|
||||
def get_metrics(
|
||||
metric: str = Path(
|
||||
...,
|
||||
title='Metric',
|
||||
description='The metric needed. Must be one of "bets", "deposits" or '
|
||||
'"registrations"',
|
||||
regex=r'^(bets$)|(deposits$)|(registrations$)',
|
||||
),
|
||||
Mount(
|
||||
'/bower_components',
|
||||
StaticFiles(directory='../bower_components'),
|
||||
name='bower_components',
|
||||
),
|
||||
]
|
||||
earliest: str = Header(None, title='Earliest time',),
|
||||
):
|
||||
var = MetricResponse(metrics='s')
|
||||
return {'metric': 's'}
|
||||
|
||||
app = Starlette(debug=True, routes=routes)
|
||||
|
||||
class Item(BaseModel):
|
||||
name: str
|
||||
description: str = None
|
||||
price: float
|
||||
tax: float = None
|
||||
|
||||
|
||||
@app.post("/items/")
|
||||
async def create_item(item: Item):
|
||||
return item
|
||||
|
||||
@@ -25,13 +25,12 @@
|
||||
<script type="text/javascript" src="{{ url_for('node_modules', path='/@fortawesome/fontawesome-free/js/fontawesome.min.js') }}"></script>
|
||||
<!-- fakeloader js -->
|
||||
<script type="text/javascript" src="{{ url_for('node_modules', path='/jq-fakeloader/js/fakeLoader.js') }}"></script>
|
||||
<!-- begin document -->
|
||||
<!-- load scripts -->
|
||||
<!-- <div class="fakeLoader"></div> -->
|
||||
<script type="text/javascript">
|
||||
$.fakeLoader({'timeToHide':1200, 'spinner':'spinner4', 'bgColor': '#00003c'});
|
||||
</script>
|
||||
<script type="text/javascript">$('.toast').toast()</script>
|
||||
<!-- begin document -->
|
||||
<div class="jumbotron">
|
||||
<h1 class="display-4">Hello, world! <i class="fas fa-globe-europe"></i></h1>
|
||||
<p class="lead">This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.</p>
|
||||
|
||||
Reference in New Issue
Block a user