A
A
Alex2017-03-06 19:10:40
Django
Alex, 2017-03-06 19:10:40

Why is sorl.thumbnail not outputting html?

Actually a question in a subject.

#model.py
class PostImages (models.Model):
  post = models.ForeignKey (Post, null='True', blank='True')
  image = models.ImageField(upload_to=None, height_field=None, width_field=None)
  def thumb(self):
    return '<img src="%s"/>' % (get_thumbnail(self.image, "50x50", crop='center', quality=95).url)
    thumb.short_description = 'Photos'
    thumb.allow_tags = True
#admin.py
class PostImagesAdmin(AdminImageMixin, admin.ModelAdmin):
  list_display = ('thumb',)

Result: <img src="/media/cache/a0/ea/a0ea41909eac756782605133045bc66a.jpg"/>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2017-03-06
Sch

return mark_safe('<img src="%s"/>' % ( ...
https://docs.djangoproject.com/en/1.10/ref/utils/#...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question