Question

I am using django easy_thumbnail in a project and I follow the instructions step by step. But i turns out that the url is not returned.

The model containing imageField is:

class Project(models.Model):
   name = models.CharField(max_length=100)
   description = models.CharField(max_length=2000)
   startDate = models.DateField(auto_now_add=True)
   photo = models.ImageField(upload_to="projectimg/", null=True, blank=True)

And in the setting, i specify:

    THUMBNAIL_ALIASES = {
    '': {
        'avatar': {'size': (50, 50), 'crop': True},
    },
    }

And I use the template filter:

<div class="image">
    <img src="{{ MEDIA_URL }}{{ project.photo|thumbnail_url:'avatar'}}" class="img-responsive" alt="{{ project.name }}">
</div>

However, the filter seems not returning any thing. Is it because that the url is not found? Or other reasons? Thanks for your time!

Was it helpful?

Solution

The problem could be one of two things, either the user that your wsgi app runs under doesn't have the right permissions to the directory where the thumbnails are generated (most likely), or Pillow isn't properly installed with the correct support.

Fixing the permissions in my case was checking what user gunicorn runs under, i checked the gunicorn conf file and created user=www-data which was user 33, I then changed directory to where the thumbnails are stored, one directory above and made user id 33 the owner:

chown -R 33:2000 filer_public_thumbnails

Now restart your application.

The other less likely problem is Pillow not having the right image support.

1) uninstall Pillow

sudo pip uninstall Pillow

2) Install all required libraries (Ubuntu)

 sudo apt-get install libtiff4-dev libjpeg8-dev zlib1g-dev \
 libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev python-tk

(Centos)

sudo yum install python-devel
sudo yum install libjpeg-devel
#Then..
sudo yum install gcc gcc-c++ 
sudo yum install zlib-devel

and reinstall Pillow

sudo pip install Pillow

See if you have the right support now and restart your app server.

OTHER TIPS

This question is a bit old but I was running into the same problem (using OS X Mavericks 10.9.2) where I would put {{ MEDIA_URL }} and that would show up but the second part wasn't. So I figured I would answer this question (which I came across during my search for an answer).

First things first: The user freylis in a comment on the question is right. You do not need

{{ MEDIA_URL }}

at all.

One of the first things I did was modify my settings.py:

THUMBNAIL_DEBUG = True

And that gave me some debugging information. Now the information was misleading as it was telling me the path and file that the second part was creating didn't exist...which I could see that it did on the server side.

After a bit of digging around I learned that maybe I needed to install the library for the image type I was working with (on command line using homebrew):

brew install libjpeg

Once I did that I uninstalled and reinstalled Pillow:

pip uninstall Pillow
pip install Pillow --upgrade

I believe the "--upgrade" will compile new libraries for it to use (in this case libjpeg) instead of using only the compiled libraries it had before when it was installed the first time.

Once I did this I was able to refresh my site and the picture started showing up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top