My current code returns a crazy number of rows with no data. Not sure what I'm doing wrong with the for loop in the jinja2 template. I tried using {{ tables[0][0] }} inside the for loop but receive error.
jinja2.exceptions.TemplateSyntaxError: expected token ':', got '}'
Would it be better to use something like jquery to create the HTML table from JSON?
app.py (shortened code)
@app.route('/', methods=['GET', 'POST'])
def index():
def stockOwnership(ticker):
...
# prints dataframe to html
table_13D = df_13D.to_json(orient='records')
table_13F = df_13F.to_json(orient='records')
print(table_13D)
#variables holding functions to be passed into tables list
ownership = stockOwnership(stock)
return render_template('index.html', tables=[ownership])
index.html
{% extends 'base.html' %}
{% block title %}
<title>Stock Info</title>
{% endblock %}
{% block body %}
<h1>Ownership</h1>
<center><h4 class="title-name">13D/G Filings</h4></center>
<table class="table table-striped", id='13D'>
<thead>
<tr class="bg-info">
<th>File Date</th>
<th>Form</th>
<th>Investors</th>
<th>Shares</th>
</tr>
</thead>
<tbody id="mydata">
{%for data in tables[0][0]%}
<tr>
<td>{{data.File_Date}}</td>
<td>{{data.Form}}</td>
<td>{{data.Investors}}</td>
<td>{{data.Shares}}</td>
</tr>
{%endfor%}
</tbody>
</table>
json via {{ tables[0][0] }}
[
{
"File_Date":"2020-04-29",
"Form":"13D\/A",
"Investors":"ARMISTICE CAPITAL, LLC",
"Shares":"407,373"
},
{
"File_Date":"2020-03-23",
"Form":"13G",
"Investors":"INTRACOASTAL CAPITAL, LLC",
"Shares":"3,517,022"
},
{
"File_Date":"2020-03-12",
"Form":"13G",
"Investors":"Sabby Management, LLC",
"Shares":"6,000,000"
},
]