Skip to content

Implementation of minimal web portal consuming our API REST #16 #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import uvicorn
from fastapi import FastAPI
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates

from code import data

app = FastAPI()
templates = Jinja2Templates(directory="templates")

# Load the data in dataframe format
df = data.getDataframe()


@app.get('/')
def root():
return {'message': 'Hello world!'}
def root(request:Request):
return templates.TemplateResponse("root.html", {"request":request})


@app.get('/tests')
def list_tests():
def list_tests(request:Request):
print("Number of manufacturers of covid tests unique: ", len(list(df['manufacturer'].unique())))
return list(df['manufacturer'].unique())

manufacturers = list(df['manufacturer'].unique())
print(manufacturers)
return templates.TemplateResponse("tests_manufacturers.html", {"request": request, "list": manufacturers})

if __name__ == '__main__':
uvicorn.run('main:app', host='0.0.0.0', reload=True)
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
uvicorn~=0.15.0
fastapi~=0.68.1
pandas~=1.3.3
requests
requests
jinja2
14 changes: 14 additions & 0 deletions templates/root.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<body>

<h1>Minimal web portal consuming our API REST about Covid-19 tests</h1>

<h3>Information about Covid-19:</h3>
<ul>
<li><a href="/">Root</a></li>
<li><a href="/tests">Manufacturers of covid tests</a></li>
</ul>

</body>
</html>
24 changes: 24 additions & 0 deletions templates/tests_manufacturers.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<body>

<h1>Minimal web portal consuming our API REST about Covid-19 tests</h1>
<p><a href="/">Main page</a></p>
<h3>Manufacturers of covid tests:</h3>

<table class="default">
<tr>
<th>Manufacturers</th>
</tr>
<tbody>
{% for id in list %}
<tr>
<td>{{id}}</td>
</tr>
{% endfor %}
</tbody>

</table>

</body>
</html>