Home > Mobile >  Im managed to display values of a table in html with flask and python but i dont understand the logi
Im managed to display values of a table in html with flask and python but i dont understand the logi

Time:09-14

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 %}

CodePudding user response:

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.

  • Related