【发布时间】:2012-05-06 03:57:56
【问题描述】:
我的场景
我正在使用 django-storage 通过 Amazon S3 提供文件。 这意味着当我执行 ./manage.py collectstatic 时,文件将保存在我在亚马逊的存储桶中,而不是本地文件系统中。
要压缩我所做的文件:“./manage.py compress” 这给出了这个错误:
Error: An error occurred during rendering: [Errno 2] No such file or directory: u'/home/user/project/static/less/bootstrap.less'
因为该文件不在我的本地文件系统上。
“由于 Django Compressor 处理文件的方式,它要求要处理的文件(在 {% compress %} 块中)在本地文件系统缓存中可用。” http://django_compressor.readthedocs.org/en/latest/remote-storages/
问题
如何使 django-compress 与 django-storage (amazon s3) 一起工作?
到目前为止我尝试过的事情
在本地和 S3 上制作 collectstatic 保存文件。由于在 django-compressor 页面的文档中提到了它,因此应该有一些好的方法来做到这一点。怎么样?
配置
STATIC_URL = 'http://mybucket.s3-website-eu-west-1.amazonaws.com/'
STATIC_ROOT = os.path.join(PROJECT_DIR,"static/")
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
)
STATICFILES_STORAGE = DEFAULT_FILE_STORAGE = 'index.storage.CachedS3BotoStorage' #defined as it is in the documentation
AWS_ACCESS_KEY_ID = "xxx"
AWS_SECRET_ACCESS_KEY = "xxx"
AWS_STORAGE_BUCKET_NAME = "xxxx"
COMPRESS_URL = STATIC_URL
COMPRESS_OFFLINE = True
COMPRESS_PRECOMPILERS = (
('text/less', 'lessc {infile} {outfile}'),
)
【问题讨论】:
标签: django django-storage