【发布时间】:2020-07-08 20:44:52
【问题描述】:
我已经设置了一个流文件,并且除了图像之外的所有块都可以工作。我知道我一定忽略了一些明显的事情。显示图像。它只是忽略了html。在我的 models.py 中,我有:
content = StreamField(
[
("title_and_text", blocks.TitleTextBlock()),
("full_rich_text", blocks.RichTextBlock()),
("simple_rich_text", blocks.LimitedRichTextBlock()),
("image_float_left", blocks.ImageChooserBlock()),
],
null=True,
blank=True,
)
在我的页面 html 中,我有:
{% for block in page.content %}
{% include_block block %}
{% endfor %}
所有其他块都正确显示。在我的 blocks.py 中,我有:
class ImageFloatLeftBlock(ImageChooserBlock):
"""Float an image to the left"""
class Meta:
template = "streams/image_float_left_block.html"
icon = "doc-full"
label = "Float Image Left"
html 文件被忽略。为了确定,我把和 h1 放进去。正在显示图像。我假设它不是在查看streams/image_float_left_block.html 文件。它确实适用于以相同方式设置的其他字段。例如,这个有效:
class TitleTextBlock(blocks.StructBlock):
"""Title and text and nothing else."""
title = blocks.CharBlock(required=True, help_text="The heading for the block")
text = blocks.TextBlock(required=True, help_text="The body of the block")
class Meta:
template = "streams/title_text_block.html"
icon = "edit"
label = "Title & Text"
我怀疑它是调用中的父类:
class ImageFloatLeftBlock(ImageChooserBlock):
我在块导入中找不到更合适的内容。什么是合适的父类,还是有其他问题?
【问题讨论】: