Wagtail 博客示例图库图片未加载

Wagtail blog example gallery image not loading

我正在按照“入门”页面上的博客教程进行操作,并且添加了 BlogPageGalleryImage。我已经完成了所有迁移,并且能够将图像添加到我之前作为管理员创建的 post。

模板和模型已全部按要求修改。

但是当我查看页面时,图像没有显示。

以下是相关代码摘录。

Model.py

class BlogIndexPage(Page):
    intro = RichTextField(blank=True)

    def get_context(self, request):
        # Update context to include only published posts, ordered by
        # reverse-chron
        context = super(BlogIndexPage, self).get_context(request)
        blogpages = self.get_children().live().order_by('-first_published_at')
        context['blogpages'] = blogpages
        return context

    content_panels = Page.content_panels + [
        FieldPanel('intro', classname="full")
    ]


class BlogPage(Page):
    date = models.DateField("Post date")
    intro = models.CharField(max_length=250)
    body = RichTextField(blank=True)

    search_fields = Page.search_fields + [
        index.SearchField('intro'),
        index.SearchField('body'),
    ]

    content_panels = Page.content_panels + [
        FieldPanel('date'),
        FieldPanel('intro'),
        FieldPanel('body', classname="full"),
        InlinePanel('gallery_images', label="Gallery images"),
    ]


class BlogPageGalleryImage(Orderable):
    page = ParentalKey(BlogPage, related_name='gallery_images')
    image = models.ForeignKey(
        'wagtailimages.Image', on_delete=models.CASCADE, related_name='+'
    )
    caption = models.CharField(blank=True, max_length=250)

    panels = [
        ImageChooserPanel('image'),
        FieldPanel('caption'),
    ]

blog_page.html

{% extends "base.html" %}

{% load wagtailcore_tags wagtailimages_tags %}

{% block body_class %}template-blogpage{% endblock %}

{% block content %}
<h1>{{ page.title }}</h1>
<p class="meta" >{{ page.date }}</p>

<div class="intro" >{{ page.intro }}</div>

{{ page.body|richtext }}

{% for item in page.gellery_images.all %}
<div style="float: left; margin: 10px" >
    {% image item.image fill-320x240 %}
    <p>{{ item.caption }}</p>
</div>
{% endfor %}
<p><a href="{{ page.get_parent.url }}" >Return to blog</a></p>

{% endblock %}

@gasman 评论

In the template, you've misspelled gallery_images as gellery_images

解决了问题。