【问题标题】:Original image size in sorl-thumbnailsorl-thumbnail 中的原始图像大小
【发布时间】:2015-06-28 20:03:19
【问题描述】:

我安装了 sorl-thumbnail 以便在画廊中有一个小的缩略图(在我的 django 项目中 - django-1.8)。但是图片和原图一样大。

模板中的代码

            {% for image in gallery %}
                {{ image.title }} <br>
                {% thumbnail image "100x100" as im %}
                    <img src="{{ image.paint.url }}" width="{{ image.width }}" height="{{ image.height }}"><br>
                {% endthumbnail %}
                {{ image.status }}<br>
                {{ image.price }}<br>
            {% endfor %}

我的模型

    class Paint(models.Model):
        title = models.CharField(max_length=200)
        gallery = models.ForeignKey(Gallery)
        paint = ImageField(upload_to='paint/%Y/%m/%d')
        price = models.CharField(max_length=50, blank=True, null=True)
        status = models.CharField(choices=STATUS_PAINT, default=AVAILABLE, max_length=50)

        class Meta:
            verbose_name = "Picture"
            verbose_name_plural = "Images"

        def __unicode__(self):
            return "{}".format(self.title)

【问题讨论】:

    标签: python django thumbnails sorl-thumbnail


    【解决方案1】:

    您应该使用im 缩略图而不是原来的image

    <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
    

    【讨论】:

    • 我更改了代码并得到:[21/Apr/2015 15:06:01]"GET /media/cache/65/bf/65bf355e8d28a891272d89738b60c6b7.jpg HTTP/1.1" 404 1905 [21/Apr/2015 15:06:01]"GET /media/cache/df/50/df5081acc1ea85d9399faae408dbc9a1.jpg HTTP/1.1" 404 1905 [21/Apr/2015 15:06:01]"GET /media/cache/32/26/3226da140f636d6973937dfd07d63878.jpg HTTP/1.1" 404 1905 [21/Apr/2015 15:06:01]"GET /media/cache/0a/13/0a13b0f59675d4bb1de6000ff2e50cb9.jpg HTTP/1.1" 404 1905 [21/Apr/2015 15:06:01]"GET /media/cache/54/4a/544a3b2cce7a514e36473eb3e543c488.jpg HTTP/1.1" 404 1905
    • 默认情况下sorl-thumbnail 将缩略图保存在媒体根目录的cache 子目录中。所以它工作正常。检查您的媒体文件的服务。
    猜你喜欢
    • 2011-07-31
    • 2015-01-16
    • 2012-06-17
    • 2017-08-09
    • 2018-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-26
    相关资源
    最近更新 更多