sorl-thumbnail not creating thumbnails

2019-02-24 11:06发布

I'm having some difficulty with sorl-thumbnail.

My template is as follows:

{% thumbnail project.image "75x75" crop="center" as im %}
<img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
{% empty %}
<p>:(</p>
{% endthumbnail %}

In my rendered webpage I get the following path for the thumbnail:

<img src="/media/cache/ff/29/ff299c50543aa807b0fbd28faf271e63.jpg" width="75" height="75">

Now this all makes sense because my MEDIA_URL is set as /media/ which is mapped in my apache httpd.conf to a local folder on my server.

The problem is that this path does not exist on the server so the image is displayed as a broken link.

It's worth noting I am using a custom storage object although this shouldn't affect things as it's passed straight through the sorl.thumbnail ImageField. Also I am using a memcached cache backend running on the server.

The annoying thing is that I don't get any errors even though I have THUMBNAIL_DEBUG and DEBUG on so it's difficult to see what's going wrong. I'm fairly sure it's failing to write the thumbnail files to disk but returning as successful because the {% empty %} statement doesn't get triggered and the appropriate cache files do not appear on the server. I don't know why though due to the lack of any error.

I'm kinda stuck at this point so any help would be appreciated.

EDIT:

I've given up with sorl now and am using easy-thumbnails instead which is working fine.

2条回答
女痞
2楼-- · 2019-02-24 11:56

Sorl did not create thumbnails for us because we used urls that were incorrectly encoded. They would contain '+' instead of ' ' or '%20' for spaces and sorl would re-encode them to '%2B' ('+' encoded). The resulting url error was suppressed and the thumbnail creation was ignored. Maybe it helps someone with this problem.

查看更多
Animai°情兽
3楼-- · 2019-02-24 12:00

I have had very similar problem with you, I cannot use easy-thumbnails because I need to create thumbnails from external source. what I have figured out is on staging is using the same database as development, so after I rendered the images on development, it stores the cached filenames into database, and when you try to render on staging, it picks up the filenames from the same database, but obviously the files are not on staging.

Try running

./manage thumbnail clear
查看更多
登录 后发表回答