2017-03-26 3 views
0

私は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

+0

'./manage.py makemigrations thumbnail'とは何ですか? –

+0

ありがとう、それは解決策でした。できます。 – singertwist

答えて

0
SORLキーと値の保存のための

ませDBテーブル。

./manage.py makemigrations thumbnail 
./manage.py migrate 
関連する問題