Just created my first fast api interface. Quite simple. I want to display a list of rows on the page.
python code is:
## ----------------------------------------------------------------------------------
## Collect data
## ----------------------------------------------------------------------------------
idb = sqle.db_engine(tg_db_name, data_path)
idb.connect()
rows = idb.ticker_list()
idb.close_db()
## ----------------------------------------------------------------------------------
## Main
## ----------------------------------------------------------------------------------
templates = Jinja2Templates(directory="templates")
app = FastAPI()
@app.get("/")
def index(request: Request):
# print(dir(request))
# return{"Hello":"DashBoard", "Stocks" : rows}
return templates.TemplateResponse("index.html", {"request": request, "Stocks": rows})
when not commented, the following line displays the rows information information
return{"Hello":"DashBoard", "Stocks" : rows}
when not commented, this one just returns an empty page. Just "Stocks" is displayed at the top.
return templates.TemplateResponse("index.html", {"request": request, "Stocks": rows})
here below the index.html template
<html>
<head>
<tile>Stocks</title>
</head>
<body>
<table>
{% for row in rows %}
{{ rows.id }}
{% endfor %}
</table>
</body>
</html>
also, row type is <class 'list'>
and it is the retreival of an sqllite query.
mySql = ('''SELECT id_ticker, tx_ticker_symbol, tx_ticker_code,
tx_ticker_name, tx_ticker_fullname
FROM Ticker''')
self.cursor.execute(mySql)
rows = self.cursor.fetchall()
return rows
I would expect the following line to display the rows information.
return templates.TemplateResponse("index.html", {"request": request, "Stocks": rows})
Also, I don't understand why rows is return as a list and not a dictionary.