【问题标题】:How could I get the latest blog posts for Mezzanine page?我怎样才能获得夹层页面的最新博客文章?
【发布时间】:2019-06-14 08:10:23
【问题描述】:

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

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

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

【问题讨论】:

  • 请更好地解释您想要实现的目标,我很乐意提供帮助。
  • @raydel-miranda 我想在我的主页上列出最新的帖子,类似于 blog_post_list.html 模板上显示的内容,但使用不同的 HTML 并且无需修改 blog_post_list.html 模板。

标签: python django content-management-system mezzanine


【解决方案1】:

我找到了答案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>

【讨论】:

    猜你喜欢
    • 2017-08-12
    • 1970-01-01
    • 2013-12-30
    • 1970-01-01
    • 1970-01-01
    • 2011-06-04
    • 1970-01-01
    • 2017-05-25
    • 2018-03-21
    相关资源
    最近更新 更多