I'm using sorl-thumbnail in django. I followed the installation guide. But thumbnail seems not working. It cannot generate cache folder under MEDIA_URL. Also, I checked my mysql database. Table thumbnail_kvstore is always empty.
In urls.py:
In models.py:
In template:
It turns out that the im.url generated by thumbnail looks like "/media/cache/6f/9d/6f9dc8d01bf2a23448525d0902a63cd6.jpg". But there isn't a cache folder generated under media/. And thumbnail_kvstore in my database is always empty. Can anyone help me here?
-- In settings.py:
INSTALLED_APPS = (
...
'sorl.thumbnail',
)
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/').replace('\\','/')
MEDIA_URL = '/media/'
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
}
}
In urls.py:
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
In models.py:
from sorl.thumbnail import ImageField
class Image(models.Model):
file = models.ImageField(upload_to="images")
user = models.ForeignKey(User)
In template:
{% thumbnail image "100x100" crop="center" as im %}
<img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
{% endthumbnail %}
It turns out that the im.url generated by thumbnail looks like "/media/cache/6f/9d/6f9dc8d01bf2a23448525d0902a63cd6.jpg". But there isn't a cache folder generated under media/. And thumbnail_kvstore in my database is always empty. Can anyone help me here?
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9ef6b7bd-abb3-4edd-a831-b8e572768285%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment