问题描述
我尝试在Page中呈现子页面的StreamField.我无法在StreamField中呈现不同的StructField.这是我的代码
I try to render a StreamField of a child page in a Page. I don't manage to render the different StructField within the StreamField. Here is my code
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是此页面的子级.)
my template. (DefinitionPage is a child of this page.)
{% 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添加自定义模板,但没有成功.
post.title is ok but it's like there is no block in post.body.I tried so many things and {% include_block block %} is certainly wrong. I also tried to add a custom template for the StructBlock without success.
我该怎么办?我正在使用Django 2.0和wagtail 2.0(我是wagtail的新手,但我阅读了文档)最好的问候
How can I do ? I am using Django 2.0 and wagtail 2.0 (I'm new to wagtail but I read the doc)Best regards
推荐答案
您需要使用 page.get_children.specific
- get_children
仅返回基本的 Page所有页面类型共有的
信息,其中不包括 DefinitionPage
中的 body
字段.
You need to use page.get_children.specific
- get_children
only returns the basic Page
information common to all page types, which doesn't include the body
field in DefinitionPage
.
这篇关于在Wagtail中访问Page.get_children的StreamField中的StructBlock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!