Wa中的轮播图片出现问题 [英] Trouble with Carousel images in Wagtail

查看:31
本文介绍了Wa中的轮播图片出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Django的新手,并且是Wagtail的完整入门者.

I'm relatively new to Django and a complete beginner in Wagtail.

我正在建立的网站上只有一个轮播,它位于首页上.我在 models.py 中创建了以下两个模型:

The website I am building only has one carousel and it is on the homepage. I have created the following two models in models.py:

class CarouselItem(Orderable):
    image = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+'
    )
    caption = models.CharField(max_length=255, blank=True)
    page = ParentalKey('HomePage', related_name='carousel_items')

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

class HomePage(Page):
    nila_intro = RichTextField(blank=True)

    content_panels = Page.content_panels + [
            InlinePanel('carousel_items', label="Carousel Items"),
            FieldPanel('nila_intro', classname="full"),
        ]

    class Meta:
        verbose_name = "Homepage"

为了正确使用模板标签,我访问了Github上的Wagtail演示站点,尝试复制已经完成的操作.

In order to get the template tags right I referred to the Wagtail Demo site on Github to try and replicate what has already been done.

基本操作,例如 {%if page.carousel_items%} {%for page.carousel_items.all%} {{carousel_item.caption}} 正常工作.同样在管理员中,一切都完全符合我的预期.

Basic operations such as {% if page.carousel_items %}, {% for carousel_item in page.carousel_items.all %} and {{ carousel_item.caption }} work just fine. Also in the admin everything is exactly as I intended.

但是我在显示图像和/或图像 src 网址时遇到了问题.我已经尝试将以下内容添加到 src 中,但未发生任何事:{{carousel_item.image.url}},然后尝试完全删除< img> 标记,做一个 {%image carousel_item.image alt =幻灯片图像"%} ,这给了我一个错误.所以我不太确定该怎么做!

I am however having issues getting the images and/or image src url's to show. I have tried both adding the following to the src and nothing happened: {{ carousel_item.image.url }} and then I tried removing the <img> tag altogether and doing a {% image carousel_item.image alt="Slide Image" %} it gave me an error. So I'm not really sure what to do!

我已包含 {%load wagtailcore_tags wagtailimages_tags%}

也许我还不太了解ModelClusters的工作方式?如我所见,你们在演示中对轮播的管理方式有所不同.

Maybe I'm not 100% clear on how ModelClusters work yet? As I saw you guys have managed carousels differently on your demo.

推荐答案

As documented at http://docs.wagtail.io/en/v1.10/topics/images.html, you need to specify a resize rule such as max-800x600 on the {% image %} tag to specify how the image should be resized when inserted into the template. If you don't want the image to be resized at all, use original:

{% image carousel_item.image original alt="Slide Image" %}

这篇关于Wa中的轮播图片出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆