一百四十一:CMS系统之根据板块过滤显示帖子

 

视图,根据传过来的板块id查数据

@bp.route('/')
def index():
board_id = request.args.get('board_id', type=int, default=None)
banners = BannerModel.query.order_by(BannerModel.priority.desc()).limit(4) # 只取4条
boards = BoardModel.query.all()
page = request.args.get(get_page_parameter(), type=int, default=1)
start = (page - 1) * config.PER_PAGE
end = start + config.PER_PAGE
if board_id:
query_obj = PostModel.query.filter_by(board_id=board_id)
posts = query_obj.slice(start, end)
total = query_obj.count()
else:
posts = PostModel.query.slice(start, end)
total = PostModel.query.count()
# bs_version: bootstrap版本
pagination = Pagination(bs_version=3, page=page, total=total)
context = {'banners': banners, 'boards': boards, 'posts': posts,
'pagination': pagination, 'current_board': board_id} # 把board_id传给前端用于渲染选中事件
return render_template('front/front_index.html', **context)

页面

效果

 

posted @ 2019-12-03 22:03  向前走。  阅读(261)  评论(0编辑  收藏  举报