'SQLAlchemy database query filter_by does not work
I am trying to select a certain 'book' from the books table and pass it to the next page on flask. However, it seems like I could not use the filter. Here is what the print statement says:
SELECT books.id AS books_id, books.title AS books_title, books.summary AS books_summary FROM books WHERE books.title = ?
Thanks for the help!
class Book(db.Model):
__tablename__ = "books"
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100), unique=False)
summary = db.Column(db.String(100), unique=False)
@app.route('/singlepage/<name>', methods=["GET", "POST"])
def singlepage(name):
print(name)
selected_book = Book.query.filter_by(title=name)
print(selected_book)
return render_template("singlepage.html", name=name, summary=selected_book)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
