缩略图不显示sorl缩略图

时间:2017-03-26 18:30:12

标签: django thumbnails sorl-thumbnail

我是Django的新手。我正在尝试在模板中使用Sorl缩略图。 但我不明白为什么它不起作用。

我可以在不使用缩略图标签的情况下显示图像(在我的模板中)。但是,当我使用它们时,它不起作用。

下面是我创建的代码:

我的模特:

from __future__ import unicode_literals

from django.db import models
from sorl.thumbnail import ImageField

def upload_location(instance, filename):
return "photos_portfolio/%s/%s/%s" %(instance.categorie, instance.slug, filename)

class Portfolio(models.Model):
title = models.CharField(max_length=200)
slug = models.SlugField(max_length=160)
image = models.ImageField(upload_to=upload_location)
timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)
updated = models.DateTimeField(auto_now=True, auto_now_add=False)
categorie = models.ForeignKey('categorie.Categorie')
article = models.ForeignKey('posts.Post')   

def __unicode__(self):
    return self.title

def __str__(self):
        return self.title

class Meta:
    ordering = ["-timestamp"]

我的观点:

def portfolio(request):
afficher = Portfolio.objects.all()
return render(request, 'portfolio.html', {'afficher': afficher})  

我的模板:

     {% for photo in afficher %}  

     <div class="image-portfolio">

     <a class="example-image-link" href="{{ photo.image.url }}" data-lightbox="example-set" data-title="Click the right half of the image to move forward.">

     {% thumbnail photo.image "100x100" crop="center" as im %}
          <img class="example-image" src="{{ im.url }}" alt=""/>
     {% endthumbnail %}    

     </a>
     </div>

    {% empty %}

    <p>No image.</p>

  {% endfor %} 

你知道我的错误在哪里吗?

提前感谢您的帮助

Singertwist

1 个答案:

答案 0 :(得分:0)

没有用于sorl键值存储的数据库表。

./manage.py makemigrations thumbnail
./manage.py migrate
相关问题