Python Forum
Dynamically Add rows to table
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dynamically Add rows to table
#1
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
Reply
#2
Ignore this. I was being an idiot. :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python script for inserting rows into hbase table lravikumarvsp 7 7,099 Mar-24-2023, 04:44 AM
Last Post: parth_botadara
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,630 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  Slittping table into Multiple tables by rows drunkenneo 1 2,047 Oct-06-2021, 03:17 PM
Last Post: snippsat
  Pandas DataFrame combine rows by column value, where Date Rows are NULL rhat398 0 2,111 May-04-2021, 10:51 PM
Last Post: rhat398
  Indexing [::-1] to Reverse ALL 2D Array Rows, ALL 3D, 4D Array Columns & Rows Python Jeremy7 8 7,105 Mar-02-2021, 01:54 AM
Last Post: Jeremy7
  write mariadb table rows query to each file? shams 1 1,873 Feb-02-2021, 04:10 PM
Last Post: buran
  Fetch Oracle DB rows & print it in HTML file with table's col headers in table format tssr_2001 1 2,983 Sep-04-2020, 01:39 PM
Last Post: ibreeden
  Printing lists in a table, rows and columns randy_shooflay 6 6,293 Sep-05-2018, 07:59 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020