我尝试使用 Django sorl-thumbnail 但它不显示图像(并且不显示任何错误)。
设置.py:
INSTALLED_APPS = (
....
'sorl.thumbnail',
)
楷模:
class Toy(models.Model):
name = models.CharField(max_length=50, verbose_name=u'Name')
image = ImageField(upload_to='site_media/images')
模板:
<div id="toy">
{% for p in toys %}
<div class="toy">
# toy.image - this is model_name.image field
{% thumbnail toy.image "100x700" as im %}
<img style="margin:{{ im|margin:"100x700" }}" src="{{ im.url }}" width="{{ im.x }}" height="{{ im.y }}">
{% endthumbnail %}
<p>
<span> {{ p.name }} </span>
<span> {{p.unit_price}} </span>
</p>
</div>
{% endfor %}
</div>
网址.py:
url(r'^site_media/(.*)$', 'django.views.static.serve', {'document_root' : os.path.join(os.path.dirname(__file__), 'site_media')}),