Python Forum

Full Version: Dynamically Add rows to table
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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 syntax

Any help would be really great.

Thanks
Ignore this. I was being an idiot. :)