我怎样才能获得夹层页面的最新博客文章?

How could I get the latest blog posts for Mezzanine page?

我是 Mezzanine 的新用户,我想在主页的自定义部分显示 8 个最新帖子。

我已经构建了查询集:BlogPost.objects.filter(publish_date__isnull=False).order_by('-publish_date')[:8]

我已经检查过 templates/blog/blog_post_list.html 但我不清楚如何将 QuerySet 结果传递给视图。

我找到了答案 Fetch blog entries with bootstrap custom theme and mezzanine。您可以使用 blog_tags 中的 blog_recent_posts 标签。加载开头的标签:

{% load blog_tags %}

以及您想重复最近帖子的位置:

<ul>
  {% blog_recent_posts as recent_posts %}
  {% for blog_post in recent_posts %}
    <li>{{ blog_post.title }}</li>
  {% endfor %}
</ul>