I use from sorl-thumbnail.
I have a model like this model
from sorl.thumbnail import ImageField
class Book(models.Model):
title = models.CharField(max_length=255)
thumb = models.ImageField(upload_to='book')
and send a book object(that i created in django admin and set a picture into django admin) to my template:
{% thumbnail book.thumb "100x100" crop="center" as im %}
<img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
{% endthumbnail %}
but my page have this error:
GET http://localhost:8000/media/cache/5b/c9/5bc90276a1fb475eb4c28816804e93fa.jpg 404 (NOT FOUND)
How I can fix this error?
My setting.py:
MEDIA_ROOT = os.path.abspath(os.path.dirname(__file__)) + '/media/'
MEDIA_URL = '/media/'
in my urls.py i have:
urlpatterns += patterns('',
(r'^media/(.*)$', 'django.views.static.serve', {'document_root': os.path.join(os.path.abspath(os.path.dirname(__file__)), 'media')}),
)
and I use from django develope server.
i use this configuration, try this lines
settings.py
SITE_ROOT = os.path.dirname(__file__)
THUMBNAIL_DEBUG = True
MEDIA_ROOT = os.path.join(SITE_ROOT, 'media')
MEDIA_URL = '/media/'
url.py
from django.conf import settings
media_root = getattr(settings, 'MEDIA_ROOT', '/media')
urlpatterns += patterns('',
url(r'^media/(?P<path>.*)$','django.views.static.serve',
{'document_root': media_root})
)