我嘗試使用Django sorl-thumbnail,但它不顯示圖像(並且沒有顯示任何錯誤)。Django sorl-thumbnail不顯示圖像
Settings.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>
urls.py:
url(r'^site_media/(.*)$', 'django.views.static.serve', {'document_root' : os.path.join(os.path.dirname(__file__), 'site_media')}),
將上述設置添加到設置文件中,仍然沒有錯誤,也沒有渲染圖像。 :/ – Amyth
非常有幫助!謝謝。 – JDavies