【问题标题】:Blog posts not listing under Wagtail homepage未在 Wagtail 主页下列出的博客文章
【发布时间】:2017-03-23 18:04:08
【问题描述】:

我已经成功地设置了本教程的开发服务器:

http://docs.wagtail.io/en/v1.9/getting_started/tutorial.html

我目前正处于“在blog/templates/blog/blog_page.html: 创建模板”这一步,并且我能够创建进入主页/博客/博客帖子但它们没有在主页/博客中列出的子页面他们在教程中做。我不知道为什么,我尝试通过将博客文章作为博客文章放置在主页/博客中来改变博客文章的显示位置,但仍然没有。

我想我不明白这里需要做什么:

from django.db import models

from wagtail.wagtailcore.models import Page
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailadmin.edit_handlers import FieldPanel
from wagtail.wagtailsearch import index


# Keep the definition of BlogIndexPage, and add:


class BlogPage(Page):
    date = models.DateField("Post date")
    intro = models.CharField(max_length=250)
    body = RichTextField(blank=True)

    search_fields = Page.search_fields + [
        index.SearchField('intro'),
        index.SearchField('body'),
    ]

    content_panels = Page.content_panels + [
        FieldPanel('date'),
        FieldPanel('intro'),
        FieldPanel('body', classname="full"),
    ]

更具体地说,# Keep the definition of BlogIndexPage, and add:

感谢您的帮助!

【问题讨论】:

  • Keep the definition of BlogIndexPage, and add 表示BlogIndexPage 的实现(类)在代码 sn-p 中没有重复,以便清楚起见(因此您专注于引入的新 BlogPage 类)和空间,但您应该将BlogIndexPage 类定义保留在文件中。换句话说,models.py 应该包含 BlogIndexPageBlogPage 类(以及所有导入)。编辑:如果这已经是您所拥有的,请分享您的 blog/models.pyblog/templates/blog/blog_index_page.html 的全部内容。
  • @LoïcTeixeira 我相信我有。这是models.py > pastebin.com/8hyxezHv / blog_index_page.html > pastebin.com/VrhPxg8V

标签: django wagtail


【解决方案1】:

我想通了。在我从页面本身手动导入之前,主页不会列出博客文章。它们都列在 /blog 下,该指南打算在其中显示它,直到您将其更改为也列出在主页下,我最终会设置它。谢谢大家。

【讨论】:

    猜你喜欢
    • 2017-03-16
    • 2018-01-10
    • 1970-01-01
    • 1970-01-01
    • 2019-05-17
    • 2016-04-15
    • 2020-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多