问题描述
我正在尝试在 wagtail 中实现 carousel 块,这是我的模型
Dictionary<Guid,int> map =
nmc2
.QuickLinks
.Select((x,n) => (x,n))
.ToDictionary(z => z.x.ConfigID,z => z.n);
nmc1.QuickLinks =
nmc1
.QuickLinks
.OrderBy(x => map[x.ConfigID])
.ToArray();
以上工作正常,但问题出在前端/模板中,我无法渲染图像。我是这样做的:
from wagtail.core.models import Page
from wagtail.core import blocks
from wagtail.admin.edit_handlers import FieldPanel,MultiFieldPanel,StreamFieldPanel
from wagtail.core.fields import StreamField
from wagtail.documents.blocks import DocumentChooserBlock
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.images.blocks import ImageChooserBlock
class ImageCarouselBlock(blocks.StructBlock):
image = ImageChooserBlock()
cta_link = blocks.TextBlock(required=False)
class HomePage(Page):
header_careousel = StreamField([
('image',ImageCarouselBlock()),],null=True,blank=True
)
content_panels = Page.content_panels + [
StreamFieldPanel("header_careousel"),]
它不起作用,我尝试了很多不同的方法,如下所示:
<div class="hero-header-slider">
<div class="owl-carousel ltr" id="heroHeaderSlider">
{% for image in self.header_careousel %}
<div class="item">
<img src="{{ image.value.image }}">
</div>
<a href="{{ image.value.cta_link}}">cta link</a>
{% endfor %}
</div>
</div>
这里 cta_link 正在获取,但图像 url 未获取。谁能帮我我该怎么做?
解决方法
rle(peaks)$lengths
将为您提供 Wagtail 的 image.value.image
模型的实例,它可以是 rendered using the {% image %}
tag,与定义为页面上的 ForeignKey 字段的图像相同:>
Image