I’m using sorl-thumbnail to get some images to crop.
I have a model looking like this
from django.db import models
from sorl.thumbnail import ImageField
class Photo(models.Model):
image = models.ImageField(upload_to="uploads")
and inside my template I have
{% load thumbnail %}
{% thumbnail photo.image "200x100" as im %}
<img src="{{ im.url }}">
{% endthumbnail %}
This doesn’t output anything. If i do <img src='{{photo.image.url}}'> the image displays fine within the browser. I also have sorl-thumbnail inside my INSTALLED_APPS and I sync’d the database and have the thumbnail_kvstore table setup.
Can someone help me please. What could cause the images to not be cropped or even displayed?
Your code looks fine, so the problem should come from other parts.The first thing you can do is to set
THUMBNAIL_DEBUG = Truein yoursettings.pyand see why the error occurs.Are you using
virualenvandPILfor image library? Make sure yourPILis compiled and installed withjpegandpng/gifsupport which requireslibjpegandzlib.Edit: As @DanielRoseman pointed out in the comment, you are actually using
django.db.models.ImageField, changingto
to use
sorl.thumbnail.ImageFieldinstead.