本文整理汇总了Python中models.Book.find_one方法的典型用法代码示例。如果您正苦于以下问题:Python Book.find_one方法的具体用法?Python Book.find_one怎么用?Python Book.find_one使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Book
的用法示例。
在下文中一共展示了Book.find_one方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: book_show
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import find_one [as 别名]
def book_show(book_id):
response.set_header('Content-Type', 'application/json')
prefix = get_prefix(request)
bk = Book.find_one(isbn=book_id)
if bk:
return bk.to_json(prefix=prefix)
else:
response.set_header('Content-Type', 'text/html')
abort(404, "Can't find a book with that ISBN ('%s')." % book_id)
示例2: book_put
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import find_one [as 别名]
def book_put(book_id):
response.set_header('Content-Type', 'application/json')
prefix = get_prefix(request)
bk_input = request.json
book = Book.find_one(isbn=bk_input['isbn'])
if book:
book.title = bk_input['title']
book.description = bk_input['description']
else:
response.status = 201
book = Book(bk_input['title'], bk_input['description'], bk_input['isbn'])
Book.store(book)
response.set_header('Location', prefix + '/books/' + book.isbn)
return book.to_json(prefix)