我正在尝试从book_title中检索title属性,但是却得到了<built-in method title of str object at 0x7fb554f9f238>
。我已将book_title作为参数传递给路线图,并在booktitle.html中分配了book_title的相应值
这是我的路线
@app.route('/search/<title>/',methods=['GET','POST'])
def btitle(title):
book_title = db.execute("SELECT title,author,isbn from books WHERE (title LIKE :title)",params={"title":title}).fetchall()
if request.method == 'GET':
book_title = db.execute("SELECT title,author,isbn from books WHERE (title LIKE :title)",params={"title":title}).fetchall()
if book_title:
return render_template("booktitle.html",book_title=book_title)
else:
return render_template("error.html")
else:
book_title = db.execute("SELECT title,author,isbn from books WHERE (title LIKE :title)",params={"title":title}).fetchall()
if book_title:
return redirect(url_for("book",book_title=book_title))
@app.route('/books/<book_title>/',methods=['GET','POST'])
def book(book_title):
if request.method == 'GET':
return render_template("individualbook.html",book_title=book_title)
而且,这些是booktitle.html
和individualbook.html
的html页面
{% extends "layout.html" %}
{% block title %}
{{ book }}
{% endblock %}
{% block body %}
<h1>Search results</h1>
<ul>
{% for book in book_title %}
<li>
<a href="{{ url_for('book', book_title=book_title) }}">
{{ book.title }}
</a>
</li>
{% endfor %}
</ul>
{% endblock %}
individualbook.html
{% extends "layout.html" %}
{% block title %}
Book
{% endblock %}
{% block body %}
<h1>Book Details</h1>
<ul>
<li>Title: {{ book_title.title }}</li>
<li>author: {{ book_title.author }}</li>
<li>isbn: {{ book_title.isbn }}</li>
</ul>
{% endblock %}
当我尝试获取title
,author
和isbn
的值时,我得到的Title:<built-in method title of str object at 0x7fb554f9f238>
和author
和isbn
的值为空。 / p>