From 1c7df42f70db9b19d9dc9ee1b5ffbff2c31d2ece Mon Sep 17 00:00:00 2001 From: raw Date: Sun, 10 Oct 2021 14:05:09 +0200 Subject: [PATCH 1/3] implementation of minimal web portal consuming our API REST --- main.py | 17 +++++++++++------ requirements.txt | 3 ++- templates/root.html | 14 ++++++++++++++ templates/tests_manufacturers.html | 26 ++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 templates/root.html create mode 100644 templates/tests_manufacturers.html diff --git a/main.py b/main.py index 46d0aa8..4e41da7 100644 --- a/main.py +++ b/main.py @@ -1,23 +1,28 @@ 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): + json_datos = {'message': 'Hello world!'} + 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) diff --git a/requirements.txt b/requirements.txt index f797a94..f776776 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ uvicorn~=0.15.0 fastapi~=0.68.1 pandas~=1.3.3 -requests \ No newline at end of file +requests +jinja2 \ No newline at end of file diff --git a/templates/root.html b/templates/root.html new file mode 100644 index 0000000..f36d8b2 --- /dev/null +++ b/templates/root.html @@ -0,0 +1,14 @@ + + + + +

Minimal web portal consuming our API REST about Covid-19 tests

+ +

Information about Covid-19:

+ + + + \ No newline at end of file diff --git a/templates/tests_manufacturers.html b/templates/tests_manufacturers.html new file mode 100644 index 0000000..c0e8762 --- /dev/null +++ b/templates/tests_manufacturers.html @@ -0,0 +1,26 @@ + + + + +

Minimal web portal consuming our API REST about Covid-19 tests

+

Main page

+

Manufacturers of covid tests:

+ + + + + + + + {% for id in list %} + + + + {% endfor %} + + + +
Manufacturers
{{id}}
+ + + \ No newline at end of file From 106e76ab6a5fec5d1a3c744e75b0021f3ec93d87 Mon Sep 17 00:00:00 2001 From: raw Date: Sun, 10 Oct 2021 14:07:59 +0200 Subject: [PATCH 2/3] implementation of minimal web portal consuming our API REST --- main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/main.py b/main.py index 4e41da7..41ca238 100644 --- a/main.py +++ b/main.py @@ -13,7 +13,6 @@ @app.get('/') def root(request:Request): - json_datos = {'message': 'Hello world!'} return templates.TemplateResponse("root.html", {"request":request}) From 63253e45d260d956869fd36efd09cd13cf99e159 Mon Sep 17 00:00:00 2001 From: raw Date: Sun, 10 Oct 2021 14:10:00 +0200 Subject: [PATCH 3/3] implementation of minimal web portal consuming our API REST --- templates/tests_manufacturers.html | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/templates/tests_manufacturers.html b/templates/tests_manufacturers.html index c0e8762..63cdae0 100644 --- a/templates/tests_manufacturers.html +++ b/templates/tests_manufacturers.html @@ -11,13 +11,11 @@

Manufacturers of covid tests:

Manufacturers - {% for id in list %} - - {{id}} + + {{id}} {% endfor %} -