I am new with html and I'm trying to display two lists into a table on the html page.
I can display the lists but can't get them to display as a nice table.
My code is:
from tabulate import tabulate
def some_function(a, b, c)
cols = ['Col 1', 'Col 2', 'Col3']
vals = [a, b, c]
table = [cols, vals]
table = tabulate(table, tablefmt='html')
return table
some_function(1.01, 1.03, 1.05)
This returns the following html code:
<table>
<tbody>
<tr><td>Col 1</td><td>Col 2</td><td>Col 3</td></tr>
<tr><td>1.01 </td><td>1.03 </td><td>1.05 </td></tr>
</tbody>
</table>
I am using Django so I can successfully return the html script to the website with my View but it doesn't read it as code, it appears as a string:
View:
def post(self, request):
form_c = CalculatorForm(request.POST, prefix='form_c')
try:
if form_c.is_valid():
post = form_c.cleaned_data
numbers = some_function(1.01, 1.03, 1.05)
except:
pass
args = {
'form_c': form_c, 'form_cols': numbers,
}
return render(request, self.template, args)
my html:
<div class="container">
{{ form_cols }} # <-- where I want my table
</div>