Reputation: 41433
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?
Upvotes: 3
Views: 1450
Reputation: 30453
Your code looks fine, so the problem should come from other parts.
The first thing you can do is to set THUMBNAIL_DEBUG = True
in your settings.py
and see why the error occurs.
Are you using virualenv
and PIL
for image library? Make sure your PIL
is compiled and installed with jpeg
and png/gif
support which requires libjpeg
and zlib
.
Edit: As @DanielRoseman pointed out in the comment, you are actually using django.db.models.ImageField
, changing
image = models.ImageField(upload_to="uploads")
to
image = ImageField(upload_to="uploads")
to use sorl.thumbnail.ImageField
instead.
Upvotes: 3
Reputation: 9708
Try doing a cleanup, or if that fails, clear. Documentation
This resolved the problem for me when I was getting unexpected output. Maybe it will work for you.
Upvotes: 0