def chapter(book_id):
page = request.args.get('page', 1, type=int)
all_chapter = Chapter.query.filter_by(book_id=book_id).first()
# print(type(pagination))
if all_chapter:
pagination = Chapter.query.filter_by(book_id=book_id).paginate(
page, per_page=current_app.config['CHAPTER_PER_PAGE'],
error_out=False
)
chapters = pagination.items
book = Novel.query.filter_by(id=book_id).first()
return render_template('chapter.html', book=book, chapters=chapters, pagination=pagination)
spider = DdSpider()
book = Novel.query.filter_by(id=book_id).first()
for data in spider.get_chapter(book.book_url):
chapter = Chapter(chapter=data['chapter'],
chapter_url=data['url'],
book_id=book_id)
db.session.add(chapter)
pagination2 = Chapter.query.filter_by(book_id=book_id).paginate(
page, per_page=current_app.config['CHAPTER_PER_PAGE'],
error_out=False
)
chapters = pagination2.items
return render_template('chapter.html', book=book, chapters=chapters, pagination=pagination2)
评论列表
文章目录