A
A
aial2016-12-07 16:47:38
Flask
aial, 2016-12-07 16:47:38

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 5c9fac241ecc4d7491b4a4d0b0ca8c67.PNG. 56f108e3612c441b8b14e1dcdf9e0ef1.PNGthat's what they did, but it didn't work. If you print this one, then output it 9e53e7b2f83a40c68d5c1de7558ab889.PNG. What do you advise please?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2016-12-07
@aial

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>

S
sim3x, 2016-12-07
@sim3x

Loop through the selection

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question