这个就非常简单了,只需要将将最新文章传入blog的上下文中即可
在app/blog/views.py的inject_archive函数中新增代码如下:
@bp.context_processor
def inject_archive():
# 文章归档日期注入上下文
posts = Post.query.order_by(Post.add_date)
dates = set([post.add_date.strftime("%Y年%m月") for post in posts])
# 标签
tags = Tag.query.all()
for tag in tags:
tag.style = ['is-success', 'is-danger', 'is-black', 'is-light', 'is-primary', 'is-link', 'is-info', 'is-warning']
# 最新文章
new_posts = posts.limit(6)
return dict(dates=dates, tags=tags, new_posts=new_posts)
在app/blog/templates/cate_list.html的侧边栏新增如下代码:



