sorl-thumbnail not creating thumbnails

纵然是瞬间 提交于 2019-12-20 02:26:15

问题


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.


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/12605974/sorl-thumbnail-not-creating-thumbnails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!