本文介绍了如何缩略图静态文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用sorl缩略图调整我的静态文件大小,但它不工作

I want to resize my static files with sorl thumbnail but it doesnt work

这里是我的代码

{% if not new.photo %}

{% with path="{{STATIC_URL}}/images/empty-news.jpg" %}
{% thumbnail path "80x80" crop="center" as im %}
<a href="#" class="image"><img alt="" src="{{im.url}}" class="frame2"></a>
{% endthumbnail %}
{% endwith %}

{% else %}
{% thumbnail new.photo "80x80" crop="center" as im %}
<a href="{% url news_detail new.slug %}" class="image">
<img alt="" src="{{im.url}}" class="frame2"></a>
{% endthumbnail %}
{% endif %}

如果我有图像它显示图像,但是当我没有图像我不能使用默认图像,因为缩略图不起作用

If I have image it shows image but when I dont have image I cant use default image because thumbnail doesn't work

推荐答案

对于我来说,将通常传递给 static 模板标签的路径(请注意,它假定为http协议,因此可以改进):

Ugly option that worked for me, passing in the path that you would normally pass to the static template tag (note that it assumes the http protocol, so it could be improved):

{% with 'http://'|add:request.get_host|add:STATIC_URL|add:image_path as path %}
    {% thumbnail path "720x306" crop="center" as im %}
      <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
    {% endthumbnail %}
{% endwith %}

建立静态图像的绝对路径。

This works by building up the absolute path to the static image.

这篇关于如何缩略图静态文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 19:12