def show_book_cates(book_cate): # 判断请求是否合法 if book_cate in BOOK_LIST: # print("请求合法") pass else: # print("请求不合法") abort(404) # print("用这个去区分每个不同的域名给他不同的关键词和描述 ", request.path) seo = { "title": TITLES[request.path][0], "keywords": TITLES[request.path][1], "description": TITLES[request.path][2] } book = Book() # 最新更新的30章内容 sql_newest_data = book.get_cates_newst_books_30(book_cate) # 最多阅读的30张内容 sql_most_data = book.get_cates_most_books_30(book_cate) return render_template("book_cate.html", seo=seo, books_cates=BOOK_CATES, sql_newest_data=sql_newest_data, sql_most_data=sql_most_data, form=SearchForm())
def get_cates_infos(book_cate): if is_string_validate(book_cate): print("输入数据有错误") resData = { "resCode": 404, # 非0即错误 1 "data": [],# 数据位置,一般为数组 "message": '输入数据有错误' } return jsonify(resData) if request.method == 'POST': print("捕获到了post请求 book_cate", book_cate) get_data = json.loads(request.get_data(as_text=True)) key = get_data['key'] print("key = ", key) secretKey = get_data['secretKey'] if book_cate in BOOK_LIST: print(key, " is in BOOK_LIST") print(key, secretKey) if key == 'newest': # select * from book_infos where book_cate='xiuzhen' order by book_last_update_time desc limit 3 print("newest") book = Book() sql_data = book.get_cates_newst_books_30(book_cate) resData = { "resCode": 0, # 非0即错误 1 "data": sql_data,# 数据位置,一般为数组 "message": '最新的30本图书信息查询结果' } return jsonify(resData) elif key == 'most': print("most") book = Book() sql_data = book.get_cates_most_books_30(book_cate) resData = { "resCode": 0, # 非0即错误 1 "data": sql_data,# 数据位置,一般为数组 "message": '最新的30本图书信息查询结果' } return jsonify(resData) else: resData = { "resCode": 2, # 非0即错误 1 "data": [],# 数据位置,一般为数组 "message": '参数有误' } return jsonify(resData) else: print("key is not BOOK_LIST") return 404 else: resData = { "resCode": 1, # 非0即错误 1 "data": [],# 数据位置,一般为数组 "message": '请求方法错误' } return jsonify(resData)