无法进入书籍详细页面,提示wishes没定义
来源:10-7 类变量的陷阱
怕几眼
2019-04-01
请老师帮忙`from flask import jsonify, request, render_template,flash
from app.forms.book import SearchForm
from app.libs.helper import is_isbn_or_key
from app.spider.yushu_book import YuShuBook
from app.view_models.book import BookViewModel, BookCollection
from . import web
import json
@web.route(’/book/search’)
def search():
form = SearchForm(request.args)
books = BookCollection()
if form.validate():
q = form.q.data.strip()
page = form.page.data
isbn_or_key=is_isbn_or_key(q)
yushu_book = YuShuBook()
if isbn_or_key == ‘isbn’:
yushu_book.search_by_isbn(q)
else:
yushu_book.search_by_keyword(q,page)
books.fill(yushu_book, q)
#return jsonify(books)
#return json.dumps(result),200,{‘content-type’:‘application/json’}
else:
flash(‘搜索的关键字不符合要求,请重新输入关键字’)
#return jsonify({‘msg’:‘参数校验失败’})
return render_template(‘search_result.html’,books=books)
@web .route(’/book//detail’)
def book_detail(isbn):
yushu_book = YuShuBook()
yushu_book.search_by_isbn(isbn)
book = BookViewModel(yushu_book.first)
return render_template(‘book_detail.html’,book = book,wished = [],gifts = [])
`
1回答
-
这个源代码看不出来问题,只有在运行时去看看,最终渲染的数据里有没有wishes?调试一下吧,真的很简单,断点看看变量的状态。
052019-04-02
相似问题