I’m using wagtail to manage content in my Django app. In my model, I used a structured block like so:
# prefered
class SectionBlock(blocks.StructBlock):
header = blocks.CharBlock()
content = blocks.RichTextBlock()
My page is expected to have multiple distinct headers like introduction, conclusion, etc however the template iteration keeps looping through the first header (introduction). The question is do I rename each item in my SectionBlock
class so I can directly access it in the template or there is a simpler solution?
class SectionBlock(blocks.StructBlock):
header1 = blocks.CharBlock()
content1 = blocks.RichTextBlock()
header2 = blocks.CharBlock()
content2 = blocks.RichTextBlock()
{% for block in blocks %}
{{ block.value.header1 }}
{{ block.value.header2 }}
{% endfor %}
question from:
https://stackoverflow.com/questions/65640950/looping-through-wagtail-contents 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…