Python Forum
Displaying search results
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Displaying search results
#81
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!!!
Reply
#82
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.
Reply
#83
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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020