索尔缩略图不好的网址 [英] Sorl-thumbnail bad url's

查看:123
本文介绍了索尔缩略图不好的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照说明设置了sorl-thumbnail,但是当我尝试在我的应用程序中使用模板标签时,没有任何图像出现。

I setup sorl-thumbnail according to instructions, but none of the images are appearing when I try to use the templatetags in my app.

看起来,不正确,但不清楚需要什么额外的配置。

It appears that the url's are not valid, but it's not clear what additional configuration is needed.

生成像这样的图像:

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

缓存/ ...如何解决图像请求?这些请求是相对于我的应用程序,而不是sorl-thumbnail:

How does "cache/..." get resolved to a request for an image? These requests are relative to my application, not to sorl-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

以下是settings.py中的相关行:

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/'

这是我的模板中的代码: p>

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 %}

图像肯定会上传(我查看了指定的目录在upload_to中),当我使用文件系统缓存时,它们被存储在相对于我的应用程序的目录缓存中。我更改了使用memcache来查看是否有帮助。

The image is definitely getting uploaded (I checked the directory specified in upload_to), and when I was using the filesystem cache they were getting stored in the directory cache/ relative to my app. I changed it to use memcache to see if that would help.

推荐答案

您需要正确配置MEDIA_URL。 ImageFile的url属性基本上只是一个来自底层存储后端对于开箱即用的Django,以生成FileField的URL。

You need to configure MEDIA_URL correctly. The "url" attribute of an ImageFile is basically just a pass-through from the underlying storage backend. For out-of-the-box Django, the upload_to path is appended to MEDIA_URL to generate the URL for a FileField.

你有什么:''+'cache / e5 / 25 / e5253a328b9130ecd7d820893f44b0e6.jpg'

你想要的:'/ media /'+'cache / e5 / 25 / e5253a328b9130ecd7d820893f44b0e6.jpg'

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

注意:你需要确保MEDIA_URL被别名/映射到Django将您的文件上传到(MEDIA_ROOT)的任何目录。

Note: you would need to make sure that MEDIA_URL is aliased/mapped to whatever directory Django is uploading your files to (MEDIA_ROOT).

-----编辑---- < br>
请参阅以下链接到默认Django存储后端的源代码。
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

----- EDIT ----
See the following links to the source of the default Django storage backend. 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

这篇关于索尔缩略图不好的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆