Answer the question
In order to leave comments, you need to log in
Pull entire list from Flask database using sqlalchemy?
We need to display the entire list from the database to the table, we tried to use query.all () did not work. Here is the database model . that's what they did, but it didn't work. If you print this one, then output it . What do you advise please?
Answer the question
In order to leave comments, you need to log in
The result of calling query.all() must be passed to the template context and looped over.
@app.route('/session/list', methods=['GET', 'POST'])
def session_list():
return render_template('session_list.html', items=Session_cinema.query.all())
<!doctype html>
<html>
<body>
<table>
<tr>
<th>Дата</th>
<th>Время</th>
<th>Зал</th>
<th>Цена</th>
</tr>
{% for item in items %}
<tr>
<td>{{ item.date }}</td>
<td>{{ item.time }}</td>
<td>{{ item.hall }}</td>
<td>{{ item.price }}</td>
</tr>
{% endfor %}
</table>
</body>
</html>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question