def search(): # 注意验证层 form = SearchForm(request.args) book = BookCollection() if form.validate(): q = form.q.data.strip() page = form.page.data print(q, page) isbn_or_key = is_isbn_or_key(q) yushu_book = YuShuBook() if isbn_or_key == "isbn": yushu_book.isbnSearch(q) else: yushu_book.keySearch(q) book.fill(yushu_book, q) # return json.dumps(book,default=lambda obj:obj.__dict__) else: flash('关键字错误,请重新输入关键字') # return jsonify(form.errors) return render_template('search_result.html', books=book)
def search(): wtforms = SearchForm(request.args) #传入所有参数,会自动分配验证 book = BookCollection() if wtforms.validate(): #开始进行验证,并且返回布尔值 q = wtforms.q.data.strip() #从验证中获取数据 page = wtforms.page.data is_isbn_or_key = isIsbnOrKey(q) yushuBook = YuShuBook() if is_isbn_or_key == 'isbn': yushuBook.isbnSearch(q) if is_isbn_or_key == 'key': yushuBook.keySearch(q, page) book.fill(yushuBook, q) # return json.dumps(book,default=lambda obj:obj.__dict__) else: flash('关键字错误,请重新输入关键字') # return jsonify(wtforms.errors) #返回所有错误信息 return render_template('search_result.html', books=book)
def search(): wtforms = SearchForm(request.args) book = BookCollection() if wtforms.validate(): q = wtforms.q.data.strip() page = wtforms.page.data is_isbn_or_key = isIsbnOrKey(q) yushu_book = YuShuBook() if is_isbn_or_key == 'isbn': yushu_book.isbnSearch(q) if is_isbn_or_key == 'key': yushu_book.keySearch(q, page) book.fill(yushu_book, q) else: flash('关键字错误,请重新输入关键字') return render_template('search_result.html', books=book)