Python Forum
Displaying search results - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Displaying search results (/thread-27661.html)

Pages: 1 2 3 4 5 6 7 8 9


RE: Displaying search results - card51shor - Jun-21-2020

Im a genius!! I got it going! Here's my code:

@app.route("/book", methods=["GET", "POST"])
@app.route("/book/<isbn>")
def book(isbn = None):
    search = db.execute("SELECT * FROM books WHERE isbn = :isbn", {'isbn':isbn}).fetchone()
    isbn = search[0]
    title =  search[1]
    author = search[2]
    year = search[3]
    reviews = ""
    return render_template("book.html", title=title, author=author, year=year, reviews=reviews, isbn=isbn)
Now - for the final step of the project, I have to create an option for the user to leave a review for the project.

I'm going to paste that tomorrow and mark this as complete. Hopefully u guys can help me finish it tomorrow.

Thanks!!!


RE: Displaying search results - ndc85430 - Jun-21-2020

Look at what you're passing to execute on line 4. The quotes.

Do you think you need the route that doesn't have the variable part (line 2)? On a similar note, do you need to default the parameter to None on line 3? Why or why not? At least try to think about what you're doing.


RE: Displaying search results - card51shor - Jun-21-2020

Yes I can see why I wouldnt need those. I just figure better be safe than sorry. But yes, I totally see the excess code.