Hi,
I am trying to loop over database entries for books and display them on an e-commerce page.
The books are stored in an SQLAlchemy database with information on title, author, and price.
I want to loop through the database and display the information for each book object in the database along with a picture of the book cover. However, I am not sure how to display this information correctly.
Here is the HTML code
And here is the books route leading to the page
I am trying to loop over database entries for books and display them on an e-commerce page.
The books are stored in an SQLAlchemy database with information on title, author, and price.
I want to loop through the database and display the information for each book object in the database along with a picture of the book cover. However, I am not sure how to display this information correctly.
Here is the HTML code
Code:
{% block body %}
<h1>Welcome {{ name }}</h1>
<br>
<table style="width:100%">
<thead>
<tr>
<th colspan=3 class="text-center">BOOKS FOR SALE</th>
</tr>
<tr>
{% for book in books %}
<th class="text-center">{{ books.title }}</th>
<th class="text-center">{{ books.author }}</th>
<th class="text-center">{{ books.price }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
<tr>
<td class="text-center"><img class="img-responsive" src="static/book1.jpg"/></td>
<td class="text-center"><img class="img-responsive" src="static/book2.jpg"/></td>
<td class="text-center"><img class="img-responsive" src="static/book3.jpg"/></td>
</tr>
</tbody>
</table>
{% endblock %}
And here is the books route leading to the page
Code:
@app.route('/books')
@login_required
def books_page():
books = Books.query.all()
return render_template('bookstest.html', name=current_user.username, books=books)