Sorl-thumbnail template tags do nothing
I am using sorl-thumbnail to get some cropping images.
I have a model similar to 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
{% load thumbnail %}
{% thumbnail photo.image "200x100" as im %}
<img src="{{ im.url }}">
{% endthumbnail %}
It doesn't output anything. If I do <img src='{{photo.image.url}}'>
, the image is displayed in the browser ok. I also have a sunroom thumbnail inside my INSTALLED_APPS and I sync the database and set up the thumbnail_kvstore table.
Can someone help me. What can cause images to not be cropped or even displayed?
source to share
Your code looks great, so the problem must come from other parts.
The first thing you can do is install THUMBNAIL_DEBUG = True
in settings.py
and see why the error occurs.
Are you using virualenv
and PIL
for an image library? Make sure yours is PIL
compiled and installed with support for jpeg
and png/gif
, which requires libjpeg
and zlib
.
Edit: As @DanielRoseman pointed out in a comment, you are actually using django.db.models.ImageField
by changing
image = models.ImageField(upload_to="uploads")
to
image = ImageField(upload_to="uploads")
use sorl.thumbnail.ImageField
.
source to share
Try cleaning, or if it fails, clean. Documentation
This solved the problem for me where I was getting unexpected results. This might work for you.
source to share