views.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:dingdian 作者: Blackyukun 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号