【问题标题】:help displaying thumbnail with sorl-thumbnail templatetag使用 sorl-thumbnail 模板标签帮助显示缩略图
【发布时间】:2011-07-29 07:33:28
【问题描述】:

我正在使用sorl-sorl-thumbnail-v10.12.1-8-g0b7b514

我的问题是使用 sorl-thumbnail 模板标签来显示图像。 我正在关注documentation,使用最简单的方式显示图像。

在我的模板中我有一个对象,所以我的模板到目前为止看起来像这样:

{% load thumbnail %}
<div class="post">
    <h2 class="title">{{ object.title }}</h2>
{% thumbnail object.logo "200x200" crop="center" as im %}
    <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
{% endthumbnail %}
</div>

真正的问题来了。此当前代码仅显示虚拟图像。 为了让我能够显示图像,我必须将代码更改为:

{% thumbnail object.logo "200x200" crop="center" as im %}
    <img src="{{ object.logo.url }}" width="{{ im.width }}" height="{{ im.height }}">
{% endthumbnail %}

如果我将“object”更改为“im”,那么我只会得到一个 dummyimage。 这是为什么?

【问题讨论】:

  • object.logo 中的object & logo 是什么类型?

标签: django sorl-thumbnail


【解决方案1】:

我认为在您的第二个示例中,它确实显示了图像,您只是显示原始图像,但在浏览器中按比例缩小,因此没有进行缩略图处理(没有调整大小)。

我怀疑您的设置有问题,可能是 MEDIA_URL。你能在文件系统中找到你的原始图像吗(在你的模型上由 upload_to 指定的文件夹中)?你能在 MEDIA_URL/cached 中找到缓存的版本吗?

【讨论】:

    猜你喜欢
    • 2015-06-14
    • 2012-06-12
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    • 2011-07-01
    • 2010-11-24
    • 2012-04-21
    • 2018-01-06
    相关资源
    最近更新 更多