我一直在尝试调试这个问题,我看到一些类似的线程也有同样的问题,但即使交叉检查了所有选项,我似乎仍然有问题。
我正在使用以下内容:
应用程序.py
@app.route("/Booksearch/<int:book_id>", methods=["GET", "POST"])
def Bookdetails(book_id):
if request.method == "GET":
if session["Username"] is None:
return render_template("error.html", message="Some error message.")
else:
return render_template("some.html")
在我的HTML中
<a href="{{ url_for('Bookdetails', books_id=result.id) }}">
当我点击链接时,我可以在浏览器上看到正确的book_id
(/Booksearch/123 where book_id=123
(。我不确定我做错了什么,仍然会出现以下错误。
创建URL时使用books_id
,但端点希望参数命名为book_id
(没有s
(:
def Bookdetails(book_id): <- without s
在您的模板中,您有:
<a href="{{ url_for('Bookdetails', books_id=result.id) }}"> <- with s in books
请使用正确的表格:
<a href="{{ url_for('Bookdetails', book_id=result.id) }}">