[Python] SQLite3 DB to front end in flask just creates empty tags for each row [duplicate]

Discussão em 'Python' iniciado por Stack, Setembro 26, 2024.

  1. Stack

    Stack Membro Participativo

    I've read the docs and looked at 2 different tutorials all do it the same way but my front end renders with empty tags but it creates a tag for the expect items in the database.

    The desired behaviour is that there is a p tag for each row in the feedback column of the database.

    I have a SQLite3 db, that has data in it, table created with this query: CREATE TABLE feedback(id INTEGER PRIMARY KEY autoincrement,feedback TEXT NOT NULL);

    This function gets all the data from the database

    def listFeedback():
    print("hello")
    con = sql.connect("databaseFiles/database.db")
    cur = con.cursor()
    data = cur.execute('SELECT * FROM feedback').fetchall()
    con.close()
    return data


    This renders the tempate return render_template('/sucess.html', state=True, posts=listFeedback())

    This is in the template

    {% for post in posts %}
    <div class='post'>
    <p>{{ post['feedback'] }}</p>
    </div>
    {% endfor %}


    If I have 6x items in the DB the front will have 6x empty p tags even though the feedback column has text content.

    post.feedback has same effect but just using post will fill the P tag with all columns from each row when I just want the one row.

    Continue reading...

Compartilhe esta Página