I try to use Django sorl-thumbnail but it does not display images (and does't show any errors).
Settings.py:
INSTALLED_APPS = (
....
'sorl.thumbnail',
)
Models:
class Toy(models.Model):
name = models.CharField(max_length=50, verbose_name=u'Name')
image = ImageField(upload_to='site_media/images')
templates:
<div id="toy">
{% for p in toys %}
<div class="toy">
# toy.image - this is model_name.image field
{% thumbnail toy.image "100x700" as im %}
<img style="margin:{{ im|margin:"100x700" }}" src="{{ im.url }}" width="{{ im.x }}" height="{{ im.y }}">
{% endthumbnail %}
<p>
<span> {{ p.name }} </span>
<span> {{p.unit_price}} </span>
</p>
</div>
{% endfor %}
</div>
urls.py:
url(r'^site_media/(.*)$', 'django.views.static.serve', {'document_root' : os.path.join(os.path.dirname(__file__), 'site_media')}),
Actually, using the ImageField from sorl is only necessary to automatically delete thumbnails when the original image is deleted.
sorl.thumbnail by default does not display any errors and fails silently if thumbnail creation was not successful. To see the errors, add
THUMBNAIL_DEBUG = True
to your settings.py. This should help you fix the problem.
Have you imported ImageField from sorl in model definition? It's necessary to get it working automatically.
Moreover you need to run in console ./manage.py syncdb
because in default configuration sorl keeps cached names of thumbnails in database. It has to create its own table in database for that.
Could you also show your settings of STATIC_URL, STATICFILES_DIRS, etc?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With