gpt4 book ai didi

django - 如何使用 django-cumulus 提供静态文件?

转载 作者:行者123 更新时间:2023-12-03 17:54:38 25 4
gpt4 key购买 nike

我正在尝试使用 django-cumulus用于从 Rackspace CloudFiles 提供文件。我目前只在我的本地开发服务器上使用 Django 1.4.2 进行尝试。

我可以使用 cumulus 的 syncstatic管理命令成功上传我所有的静态 Assets ,但我似乎无法在我的网站上以相同的设置显示它们。

如果我的相关设置是:

STATIC_URL = '/static/'
CUMULUS = {
'USERNAME': 'myusername',
'API_KEY': 'myapikey',
'CONTAINER': 'mycontainername',
'STATIC_CONTAINER': 'mycontainername',
}
DEFAULT_FILE_STORAGE = 'cumulus.storage.CloudFilesStorage'
STATICFILES_STORAGE = 'cumulus.storage.CloudFilesStaticStorage'

然后当我运行 syncstatic我所有应用的静态文件都上传到 /mycontainername/static/ ,正如我所料。但是当我在管理员中加载一个页面时,它会忽略 STATIC_URL并尝试从 http://uniquekey....r82.cf2.rackcdn.com/path/to/file.css 等 URL 提供 Assets 而不是 http://uniquekey....r82.cf2.rackcdn.com/static/path/to/file.css .

另外,我看不到如何让我的公共(public)(非管理员)页面使用 CloudFiles 上的静态文件,而不是从本地 /static/ 提供它们。目录。

我错过了一些关键的设置,还是我做错了什么?

最佳答案

我有同样的问题。我所做的是

git 克隆 https://github.com/richleland/django-cumulus.git

编辑 context_processors.py

from django.conf import settings

from cumulus.storage import CloudFilesStorage

def cdn_url(request):
"""
A context processor to expose the full cdn url in templates.

"""
cloudfiles_storage = CloudFilesStorage()
static_url = '/'
container_url = cloudfiles_storage._get_container_url()
cdn_url = container_url + static_url

print {'CDN_URL': cdn_url}

return {'CDN_URL': cdn_url}

完成后,使用 sudo python setup.py install 安装它

请注意,来自 django cumulus 的 context_processors.py 实际上很慢

关于django - 如何使用 django-cumulus 提供静态文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13307781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com