Python sorl缩略图未在Django模板中显示图像

Python sorl缩略图未在Django模板中显示图像,python,django,sorl-thumbnail,Python,Django,Sorl Thumbnail,型号.py: class NewImage(models.Model): thumbnail = models.ImageField(upload_to='photos') time_created = models.DateTimeField() class ImageForm(forms.ModelForm): class Meta: model = NewImage fields = {'thumbnail'} def loadI

型号.py

class NewImage(models.Model):
    thumbnail = models.ImageField(upload_to='photos')
    time_created = models.DateTimeField()
class ImageForm(forms.ModelForm):
    class Meta:
        model = NewImage
        fields = {'thumbnail'}
def loadImages(request):
    images = NewImage.objects.all()
    context = {'images': images}
    return render(request, 'mysite/imagedisplay.html', context)
{% 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 %}
forms.py

class NewImage(models.Model):
    thumbnail = models.ImageField(upload_to='photos')
    time_created = models.DateTimeField()
class ImageForm(forms.ModelForm):
    class Meta:
        model = NewImage
        fields = {'thumbnail'}
def loadImages(request):
    images = NewImage.objects.all()
    context = {'images': images}
    return render(request, 'mysite/imagedisplay.html', context)
{% 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 %}
我已在我的模板中呈现此表单,图片已成功上载。我还可以在没有
或缩略图的情况下显示它们

视图.py

class NewImage(models.Model):
    thumbnail = models.ImageField(upload_to='photos')
    time_created = models.DateTimeField()
class ImageForm(forms.ModelForm):
    class Meta:
        model = NewImage
        fields = {'thumbnail'}
def loadImages(request):
    images = NewImage.objects.all()
    context = {'images': images}
    return render(request, 'mysite/imagedisplay.html', context)
{% 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 %}
imagedisplay.html

class NewImage(models.Model):
    thumbnail = models.ImageField(upload_to='photos')
    time_created = models.DateTimeField()
class ImageForm(forms.ModelForm):
    class Meta:
        model = NewImage
        fields = {'thumbnail'}
def loadImages(request):
    images = NewImage.objects.all()
    context = {'images': images}
    return render(request, 'mysite/imagedisplay.html', context)
{% 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 %}
{%load缩略图%}
{%用于图像中的图像%}
{{image.time_created}

{%endfor%} {%用于图像中的图像%} {%thumbnail image.thumnail“100x100”crop=“center”作为im%} {%endthumbnail%} {%endfor%}
它只显示方形框,不显示图像:

当我检查该框以查看源代码时,它会显示

而不是


我怎样才能完成这项工作?

你清除缓存了吗?我不知道怎么做。只需删除缓存文件夹,就可以了。sorl将为您生成文件@知道了吗?@rajasimon:我已经删除了缓存文件,但它仍然不工作。。。