AttributeError: 'CharField' object has no attribute 'stream_block'

AttributeError: 'CharField' object has no attribute 'stream_block'

我真的是 Python3、Django 和 Wagtail 的新手,我正在尝试创建一个 ArticlePage 模型,其中使用了 StreamField 块,但 运行 遇到了问题并收到错误:

AttributeError: 'CharField' 对象没有属性 'stream_block' 错误。

我不知道我做错了什么?

我显然做错了什么但不知道是什么?

这是 model.py 代码:

articles/models.py:

from modelcluster.fields import ParentalKey
from wagtail.core import blocks
from wagtail.core.models import Page, Orderable
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel, MultiFieldPanel, InlinePanel
from wagtail.core.fields import StreamField
from streams import blocks


from wagtail.core.fields import RichTextField
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.search import index

### Flexible Page
# Create your models here.
class ArticlePage(Page):
    subtitle = models.CharField()
    body = RichTextField()
    date = models.DateField("Article date")
    team_member = models.CharField()
    feed_image = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+'
    )

    search_fields = Page.search_fields + [
        index.SearchField('body'),
        index.FilterField('date'),
        index.FilterField('subtitle'),
    ]

    template = "articles/article_page.html"
    #ToDo: add StreamFields
    content = StreamField(
        [
            ("team_member", blocks.TeamMembersBlock())
        ],
        null=True,
        blank=True,
    )

    subtitle = models.CharField()
    content_panels = Page.content_panels + [
        FieldPanel("subtitle"),
        FieldPanel('date'),
        FieldPanel('body', classname="full"),
        InlinePanel('related_links', label="Related links"),
        StreamFieldPanel("team_member"),
    ]

    promote_panels = [
        MultiFieldPanel(Page.promote_panels, "Common page configuration"),
        ImageChooserPanel('feed_image'),
    ]

    # Parent page / subpage type rules

    parent_page_types = ['articles.ArticleIndex']
    subpage_types = []

    class Meta:  # noqa
        verbose_name = "Flex Page"
        verbose_name_plural = "Flex Pages"

# Create your models here.


class ArticlePageRelatedLink(Orderable):
    page = ParentalKey(ArticlePage, on_delete=models.CASCADE,
                       related_name='related_links')
    name = models.CharField()
    url = models.URLField()

    panels = [
        FieldPanel('name'),
        FieldPanel('url'),
    ]

您的 content_panel 定义中有 StreamFieldPanel("team_member"),但您的 StreamField 被命名为 content,而不是 team_memberteam_member 是一个完全不同的领域。