【发布时间】:2018-02-25 12:41:36
【问题描述】:
我尝试在页面中呈现子页面的 StreamField。我无法在 StreamField 中呈现不同的 StructField。这是我的代码
class DefinitionPage(Page):
body = StreamField([
('definition', blocks.StructBlock([
('heading', blocks.CharBlock(label='Titre')),
('paragraph', blocks.RichTextBlock(label='Paragraphe')),
]))
])
content_panels = Page.content_panels + [
StreamFieldPanel('body'),
]
我的模板。 (DefinitionPage 是该页面的子页面。)
{% for post in page.get_children %}
<h2><a href="{% pageurl post %}">{{ post.title }}</a></h2>
{% for block in post.body %}
{% include_block block %}
{% endfor %}
{% endfor %}
post.title 没问题,但好像 post.body 中没有块。 我尝试了很多东西,{% include_block block %} 肯定是错误的。我还尝试为 StructBlock 添加自定义模板,但没有成功。
我该怎么办?我正在使用 Django 2.0 和 wagtail 2.0(我是 wagtail 的新手,但我阅读了文档) 最好的问候
【问题讨论】:
标签: django wagtail wagtail-streamfield