[FIXED] Im managed to display values of a table in html with flask and python but i dont understand the logic behind my solution

Issue

this part of code im using to Display the entries in the database on index.html

people = db.execute("SELECT * FROM birthdays")

        return render_template("index.html", name = people)

birthday database

CREATE TABLE birthdays (
id INTEGER,
name TEXT,
month INTEGER,
day INTEGER,
PRIMARY KEY(id)

and this is the html code i use to display the name, the month , and day

{% for people in name %}
   <tr>
        <td>{{ people["name"] }}</td>
        <td>{{ people["month"] }} / {{people["day"]}}</td>
   </tr>
{% endfor %}

can someone explain if i have assign

people = db.execute("SELECT * FROM birthdays")

and the variable name = people

whats the logic behind this loop ?

{% for people in name %}

Solution

I recommend you to learn python and flask structure first.

people = db.execute("SELECT * FROM birthdays")

SELECT *(mean all) will show u all records in birthday column.

{% for people in name %}

for loop provides all records in the people variable to be displayed on jinja.

Answered By – Furkan Ozkan

Answer Checked By – Clifford M. (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published