1๐
I would like to document what happened and provide some suggestions for people who are new to sorl like me:
-
Check the database cache or whatever caching backends you are using to see if there is anything under the table named thumbnail_kvstore. For what I have encountered, the original image file that I tried to generate a thumbnail from was 0 byte. Sorl did generate a key for the thumbnail even though the file is empty. However, the key itself is not stored in the database. I guess sorl would only update the database table if an actual thumbnail file has been created on the hard drive.
-
Check your hard drive. Once the thumbnail file is created, you can print out the url:
im = get_thumbnail('/Users/cheng/Dev/notes_proj/images/2015/4/8/c0eb6152bcb74c31c6eff3562513ee6507f8657d.png') print im.url
This is the print out I saw:
images/cache/e6/99/e699913d4ee776453e5c37108decb1bc.jpg
Now, go to your MEDIA_ROOT, and see if there is a new directory named cache, and see if the .jpg thumbnail is in there.
-
If you can verify that the thumbnail file is there but still getting a 404. Now go to check your urls.py, make sure you have something like this:
from django.conf import settings urlpatterns = patterns('', ... url(r'^images/(.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), )
Assuming you have set the MEDIA_URL as the following:
MEDIA_ROOT ='images/'
Adjust the name to suit your needs.
Everything should work now.
P.S. One more thing to note is that in production, you might have another server to server static files. In that case, you should remove:
url(r'^images/(.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
from your urls.py file.