Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Easy Thumbnail not working

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!

like image 790
Wei Xu Avatar asked Feb 14 '23 18:02

Wei Xu


1 Answers

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.

like image 114
radtek Avatar answered Feb 16 '23 11:02

radtek