sorl-thumbnail不在Django模板中显示图像

时间:2014-11-26 10:38:55

标签: python django sorl-thumbnail

models.py

class NewImage(models.Model):
    thumbnail = models.ImageField(upload_to='photos')
    time_created = models.DateTimeField()

forms.py

class ImageForm(forms.ModelForm):
    class Meta:
        model = NewImage
        fields = {'thumbnail'}

我已在模板中渲染此表单,图片上传成功。我也没有sorl-thumbnail显示它们。

views.py

def loadImages(request):
    images = NewImage.objects.all()
    context = {'images': images}
    return render(request, 'mysite/imagedisplay.html', context)

imagedisplay.html

{% load thumbnail %}

{% for image in images %}
    <p>{{image.time_created}}</p>
    <img src='..{{image.thumbnail.url}}' width = '50%'/>
{% endfor %}
 <!-- this displays the images but the code below doesn't work -->
{% for image in images %}
    {% thumbnail image.thumbnail "100x100" crop="center" as im %}
        <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
    {% endthumbnail %}
{% endfor %}

它只显示没有图像的方框: enter image description here

当我检查该框以查看其显示的来源<img src="/mediafiles/cache/e0/b4/e0b4ff0750a34c5c417b30058554c160.jpg" width="100" height="100">

而不是<img src="../mediafiles/photos/170_kclgRCl.jpg" width="100" height="100">

我如何开展这项工作?

0 个答案:

没有答案