我在下面有以下 StructBlock 和 StreamBlock:
class AccordionItemBlock(StructBlock):
title = CharBlock()
text = RichTextBlock()
class AccordionRepeaterBlock(StreamBlock):
accordion_item = AccordionItemBlock()
我需要以编程方式将它和多个“项目”CharBlocks 添加到此页面:
class BasicPage(Page):
body = StreamField([
('accordion_repeater_block', AccordionRepeaterBlock()),
], null=True)
这就是我接近它的方式
page.body = [
(
'accordion_repeater_block',
{
'accordion_item',
{
'title': 'Title goes here',
'text': RichText('Testing!'),
}
}
)
]
provider.save()
无论我在'accordion_repeater_block'之后的第二个元组值中输入什么,都会出错。任何想法如何解决这个问题?