Django sorl-thumbnail does not display images

I am trying to use Django sorl-thumbnail, but it does not display images (and does not 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')}), 
+8
django
source share
2 answers

Did you import ImageField from sorl into the model definition? You must make it work automatically.

Moreover, you need to run the ./manage.py syncdb console because the default configuration configuration stores cached thumbnail names in the database. To do this, he must create his own table in the database.

Could you also show your settings STATIC_URL, STATICFILES_DIRS, etc.

+3
source share

In fact, using ImageField from sorl is only necessary to automatically remove thumbnails when deleting the original image.

sorl.thumbnail by default does not display any errors and fails if the thumbnail creation was not successful. To see errors, add

 THUMBNAIL_DEBUG = True 

to your settings.py. This will help you fix the problem.

+13
source share