视图,根据传过来的板块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)
页面
效果