在我的项目Django(Django 1.8)中,我安装了sorl-thumbnail。 但缩略图不会出现。我收到错误:
在我的控制台中,我得到:
[22/Apr/2015 08:29:04]"GET /media/cache/fe/f7/fef79c8f9500649c7e8224abf81ce3b9.jpg HTTP/1.1" 404 1905
[22/Apr/2015 08:29:04]"GET /media/cache/25/a9/25a9bc15964015502d7bd8a048734c07.jpg HTTP/1.1" 404 1905
[22/Apr/2015 08:29:04]"GET /media/cache/a5/b6/a5b6b8f98ad045c9d6392feb41bc33ba.jpg HTTP/1.1" 404 1905
[22/Apr/2015 08:29:04]"GET /media/cache/20/fd/20fd944bdd086649f9d72d2117a46f67.jpg HTTP/1.1" 404 1905
[22/Apr/2015 08:29:04]"GET /media/cache/cf/b0/cfb07abdd25a38f3f0e092100c9888d5.jpg HTTP/1.1" 404 1905
[22/Apr/2015 08:29:04]"GET /media/cache/9c/2c/9c2ce4cb5cf17b937df293fecdaa4b10.jpg HTTP/1.1" 404 1905
我的一部分settings.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'public_assets')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
THUMBNAIL_DEBUG = True
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
我的网址
urlpatterns = [
url(r'^blog/', include("blog.urls", namespace="blog")),
url(r'^admin/', include(admin.site.urls)),
url(r'^ckeditor/', include('ckeditor.urls')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
模板中的代码
<table>
{% for image in gallery %}
{% if forloop.counter0|divisibleby:3 %}<tr>{% endif %}
{% thumbnail image "300x200" as im %}
<td style="padding-left:50px;padding-right:50px;">
<img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}"><br>
{{ image.title }}<br>
{{ image.status }}<br>
{{ image.price }}<br>
</td>
{% endthumbnail %}
{% if forloop.counter|divisibleby:3 or forloop.last %}</tr>{% endif %}
{% endfor %}
</table>
答案 0 :(得分:0)
运行python manage.py thumbnail clear_delete_all
,也许你有旧的链接来缓存数据库中的图像。