Open qcaron opened 9 years ago
No I did not skip it, it's in my ROOT_URLCONF
.
As my images are NOT located in the MEDIA_ROOT
but in STATIC_ROOT
, can thumbnail create thumbnails in MEDIA_ROOT/cache
for my static mages ?
Because it just looks like thumbnail tries to find my images in MEDIA_ROOT/static/main/img
and does not find them which is normal. But then how to serve thumbnails for static images ?
OK so I copied my static/main/img
in my MEDIA_ROOT
and it worked. It means that everything that can be served from sorl-thumbnails must be located in the MEDIA_ROOT
.
My conclusion: only user uploded files can be thumbnailed.
So should I cache images in my template and save resized images before serving them?
OK so I copied my
static/main/img
in myMEDIA_ROOT
and it worked. It means that everything that can be served from sorl-thumbnails must be located in theMEDIA_ROOT
.
I think this because of how Django's file storage backend. If things are outside the MEDIA_ROOT
you should see a suspicious file operation error raised by Django. I guess it is swallowed in a "too general" except-clause somewhere?
A way to work around this for static files is to prefix the static paths you pass to sorl-thumbnails with the domain name (e.g. http://example.com/static/img.png
).
Well that made me crazy at some point: I did not see any exception or warning until I gave a path outside MEDIA_ROOT
:
SuspiciousFileOperation at /
The joined path (/Users/quentin/Python/projects/static/main/img/business_man_in_the_mirror.jpg)
is located outside of the base path component (/Users/quentin/Python/projects/djangoproject).
So sorl-thumbnail is ok with my image' abstract static file because it's located under my django project path. But then it does not copy or find the static file. It really looks like a bug.
I mean, if all images must be in MEDIA_ROOT
, then not finding an abstract path should raise an error because it seems sorl-thumbnail is looking in media/static/main/img/business_man_in_the_mirror.jpg
and fails silently.
@relekang I tried your workaround and it worked. However, it created a cache
folder in my project root directory. Since media/cache
is created for media then how could agree with a cache
folder is served for static files? If it is a bit odd with DEBUG=True
and STATIC_URL='/static/'
but it is an acceptable solution for a production environment isn't it?
However, it created a cache folder in my project root directory.
That is a bit strange, I would expect it to use the regular cache folder in media.
Yes indeed. I finally decided not to go with sorl-thumbnail for my static images. Should I open a feature request for this?
Hi there, I am using MEDIA_ROOT directory but for me, images are not showing. I am using ImageField that comes from pillow as stated in a sorl-thumbnail official documention that we can use it.
Hi there !
If I do not set
MEDIA_ROOT
andMEDIA_URL
in my settings, the static/cache directory gets filled with images. But when settingsMEDIA_ROOT
andMEDIA_URL
then it does not work anymore.I am using Django 1.8.3 and Python 2.7.6 with pipeline 1.5.3. I am testing locally so please note that
DEBUG=True
,TEMPLATE_DEBUG = DEBUG
andTHUMBNAIL_DEBUG = DEBUG
.I have referenced this in a stackoverflow question but I fear I will not get an answer there. So here it is:
Here are my settings:
My home.html file contains this:
{{ business_man_in_the_mirror }}
prints "/static/main/img/business_man_in_the_mirror.jpg".{{ im.url }}
prints "/media/cache/d0/38/d038a3e64b2c7d070088e368ee881027.jpg"So far so good. But the cache folder in MEDIA_ROOT never gets created. The MEDIA_ROOT even has 777 rights. I do not see any error from
./manage.py runserver -v 3
. So the image is missing in my web page.The runserver log shows the following:
http://localhost:8000/static/main/img/business_man_in_the_mirror.jpg does show me the image.
I tried all thumbnail Management Commands but it had no effect. I also tried to delete the tumbnail_kvstore table and the cache table in DB, changed nothing. I have 5 rows in cache table but nothing in thumbnail_kvstore table.
Thanks for your help!!