![]() |
| Dynamically Add rows to table - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Dynamically Add rows to table (/thread-35459.html) |
Dynamically Add rows to table - TommyAutomagically - Nov-04-2021 Hi, I'm trying to take data from the database and display this within a table in my html template. But i want each item in the database to be shown on a new row within the table. I have a function view, which is very basic. def showInvestor(request): results=Investor.objects.all() return render(request,"pages/investors.html",{"Investor":results}) class Meta: db_table="apps_investor"and then within my html template i have <table id="datatable" class="table table-bordered dt-responsive nowrap w-100"> {% for results in Investor %} <thead> <tr> <th>Investor Name</th> <th>Investor Website</th> <th>Investror Portfolio</th> <th>Notes</th> </tr> </thead> <tbody> <tr> <td>{{results.investor_name}}</td> <td>{{results.investor_website}}</td> <td>{{results.investor_portfolio}}</td> <td>{{results.investor_comment}}</td> </tr> </tbody> {% endfor %} </table>But this clearly only shows the first item returned, so I think i need to do something like a foreach value create a new row, but I'm not sure of the syntaxAny help would be really great. Thanks RE: Dynamically Add rows to table - TommyAutomagically - Nov-04-2021 Ignore this. I was being an idiot. :) |