Sorl-thumbnail bad url's

I set the sorl-thumbnail sketch according to the instructions, but none of the images appear when I try to use templatetags in my application.

The URL seems to be invalid, but it is unclear what additional configuration is needed.

The same image is created:

<img src="cache/e5/25/e5253a328b9130ecd7d820893f44b0e6.jpg" width="100" height="100"> 

How is "cache / ..." resolving an image request? These requests relate to my application, not the thumbnail:

 [31/May/2011 07:13:05] "GET /myapp/cache/e5/25/cache/e5/25/cache/00/73/0073095ee4b968b45386ef3fec4f389c.jpg HTTP/1.1" 200 1004 

Here are the relevant lines in settings.py:

 INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', # Uncomment the next line to enable the admin: 'django.contrib.admin', 'mysite.myapp', 'sorl.thumbnail', ) CACHES = { # 'default': { # 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', # 'LOCATION': 'cache', # } 'default': { 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', 'LOCATION': '127.0.0.1:11211', } } # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash if there is a path component (optional in other cases). # Examples: "http://media.lawrence.com", "http://example.com/media/" MEDIA_URL = '' # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a # trailing slash. # Examples: "http://foo.com/media/", "/media/". ADMIN_MEDIA_PREFIX = '/media/' 

This is the code in my template:

 {% thumbnail auction.item.image "100x100" crop="center" as im %} <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}"> {% endthumbnail %} 

The image is definitely uploaded (I checked the directory specified in upload_to), and when I used the file system cache, they were saved in the / directory cache relative to my application. I modified it to use memcache to find out if that would help.

+4
source share
1 answer

You need to configure MEDIA_URL correctly. The url attribute in ImageFile is just a walk from the underlying repository. For Django ready to create a URL for FileField, the upload_to path to MEDIA_URL is added .

What do you have: '' + 'cache / e5 / 25 / e5253a328b9130ecd7d820893f44b0e6.jpg'
What do you want: '/ media /' + 'cache / e5 / 25 / e5253a328b9130ecd7d820893f44b0e6.jpg'

Note: you need to make sure that MEDIA_URL is smooth / mapped to any directory that Django downloads your files (MEDIA_ROOT).

----- EDIT ----
See the following links to the default source Django storage server source. https://code.djangoproject.com/browser/django/tags/releases/1.3/django/core/files/storage.py#L154
https://code.djangoproject.com/browser/django/tags/releases/1.3/django/core/files/storage.py#L240

+6
source

All Articles