async def search(request): ''' url http://localhost:5000/v1/book/search?q={} ''' form = BookSearchForm(data=request.raw_args) if BookSearchForm(data=request.raw_args).validate(): book=Book(request) q=form.q.data result=await book.search_by_title_or_publisher(q) if result: resp={"result":result,"flag": 1} #返回值拼接成json格式 return json(resp) return NotFound(request) return ParameterException(request)
def search(): form = BookSearchForm().validate_for_api() q = '%' + form.q.data + '%' books = Book.query.filter(or_(Book.title.like(q), Book.publisher.like(q))).all() books = [book.hide('summary').append('page') for book in books] return jsonify(books)
def search(): # url = http://localhost:5000/v1/book/search?q={} form = BookSearchForm().validate_for_api() q = "%" + form.q.data + "%" books = Book.query.filter(or_(Book.title.like(q), Book.publisher.like(q))).all() books = [book.hide("summary") for book in books] return jsonify(books)
def search(): form = BookSearchForm().validate_for_api() q = '%' + form.q.data + '%' books = Book.query.filter(Book.title.like(q)).all() if books is None or len(books) < 1: raise BookNotFound() return jsonify(books)
def search(): form = BookSearchForm().validate_for_api() # 用like模式, 查询关键词前后加%号 q = '%' + form.q.data + '%' books = Book.query.filter(or_(Book.title.like(q), Book.publisher.like(q))).all() books = [book.hide('summary', 'id') for book in books] return jsonify(books)
def search(): form = BookSearchForm().validate_for_api() q = form.q.data if is_isbn_or_key(q) == 'key': books = Book.search_by_keywords(q) else: books = [Book.get_book_by_isbn(q)] return jsonify(books), 200
def search(): form = BookSearchForm().validate_for_api() start = form.start.data count = form.count.data summary = form.summary.data q = form.q.data http = Http() res = http.book_search(start, count, summary, q) return jsonify(res)
def search(): # url http://localhost:5000/v1/book/search?q={} form = BookSearchForm().validate_for_api() q = '%' + form.q.data + '%' books = Book.query.filter(or_(Book.title.like(q), Book.publisher.like(q))).all() # 隐藏字段 books = [book.hide('summary', 'id') for book in books] return jsonify(books)
def search(): # /v1/book/search?q=python form = BookSearchForm().validate_for_api() q = f'%{form.q.data}%' # 书名 出版社 ISBN books = Book.query.filter( or_(Book.title.like(q), Book.publisher.like(q), Book.isbn.like(q))).all() books = [book.hide('summary') for book in books] return jsonify(books)
def search_book(): # url http://localhost:5000/v1/book?q={} form = BookSearchForm().validate_for_api() q = '%' + form.q.data + '%' books = Book.query.filter( and_( or_(Book.title.like(q), Book.author.like(q), Book.publisher.like(q)), Book.status == 0)).all() books = [book.hide('summary') for book in books] return jsonify(books)
def search(): """ 搜索图书 模糊检索 """ form = BookSearchForm().validate_for_api() q = '%' + form.q.data + '%' # 元类 创建ORM实例 books = Book.query.filter(or_(Book.title.like(q), Book.publisher.like(q))).all() books = [book.hide('summary') for book in books] return jsonify(books)
def search(): # url:/v1/book/search?q={} form = BookSearchForm().validate_for_api() q = '%' + form.q.data + '%' # 元类 ORM books = Book.query.filter( or_(Book.title.like(q), Book.publisher.like(q))).all() # 查询中的条件为or_(条件1或条件2);like()模糊查询 books = [book.hide('summary') for book in books] # 隐藏部分字段 return jsonify(books)
def search(): ''' url http://localhost:5000/v1/book/search?q={} ''' form = BookSearchForm().validate_for_api() q = '%' + form.q.data + '%' #模糊搜索前后要加% books = Book.query.filter(or_(Book.title.like(q), Book.publisher.like(q))).all() books = [book.hide('summary') for book in books] resp = {"result": books, "flag": 1} #返回值拼接成json格式 return jsonify(resp)
def search(): #url http://locahost:5000/v1/book/search?q={} # request.args.to_dict() 在base中完成 form = BookSearchForm().validate_for_api() # 完成验证 q = '%' + form.q.data + '%' # 模糊搜索前后得加 % # return q books = Book.query.filter(or_(Book.title.like(q), Book.publisher.like(q))).all() #like 指定关键字 q books = [book.hide('summary', 'id').append('pages') for book in books] # 只 返回指定的 关键字 # 隐藏summary,id.追加pages. return jsonify(books)
def search(): """ 根据传入的查询参数搜索图书信息 -> 用like实现模糊查询, or_在filter中表示或关系 :return: """ form = BookSearchForm().validate_for_api() q = '%' + form.q.data + '%' # # book = Book() # # 元类 ORM books = Book.query.filter(or_(Book.title.like(q), Book.publisher.like(q))).all() books = [book.hide('summary', 'id') for book in books] # 隐藏summary字段 return jsonify(books)
def search(): # 实例化,然后调用 form = BookSearchForm().validate_for_api() # 获取q。模糊搜索前后+% q = '%' + form.q.data + '%' # # sqlalchey实例化变量,不是通过普通的, book = Book()。而是通过元类 ORM创建的,,在ssqlalchey里面,不会去执行构造函数,使用装饰器 # 模糊查询sqlalchemy方法。or_意思是或关系,默认是且关系。需要导入 books = Book.query.filter(or_(Book.title.like(q), Book.publisher.like(q))).all() # 去除掉某些字段的返回,比如summary。hide方法。在book下面新建hide方法 books = [book.hide('summary') for book in books] return jsonify(books)
def search(): form = BookSearchForm(request.form).validate_for_api() q = '%' + form.q.data + '%' books = Book.query.filter( or_(Book.name.like(q), Book.category_id.like(q))).all() return jsonify(books)
def search(): form = BookSearchForm().validate_for_api() q = '%' + form.q.data + '%' books = Book.query.filter(or_(Book.title.like(q), Book.publisher.like(q))).all() return jsonify(books)
def search(): form = BookSearchForm().validate_for_api() books = Book.search_by_keywords(form.q.data) return jsonify(books)
def search(): form = BookSearchForm().validate_for_api() q = form.q.data return q