我的情景
我正在使用django-storage来通过Amazon S3提供文件.
这意味着当我执行./manage.py collectstatic时,文件将保存在亚马逊的存储桶中,而不是本地文件系统上.
要压缩我做的文件:“./ manage.py compress”
这给出了这个错误:
错误:渲染期间发生错误:[Errno 2]没有这样的文件或目录:u’/ home / user / project / static / less / bootstrap.less’
“由于Django Compressor处理文件的方式,它要求处理文件(在{%compress%}块中)在本地文件系统缓存中可用.”
http://django_compressor.readthedocs.org/en/latest/remote-storages/
题
如何使用django-storage(amazon s3)进行django-compress工作?
到目前为止我试图做的事情
在本地和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}'),)
解决方法
我认为你唯一缺少的设置是COMPRESS_ROOT.
我有django-compressor与S3非常合作.这是我的配置:
DEFAULT_FILE_STORAGE = 'g2k_utils.s3storage.S3BotoStorage' STATICFILES_STORAGE = DEFAULT_FILE_STORAGE COMPRESS_ROOT = '/home/user/website/static/' # Where my SCSS,JS files are stored COMPRESS_STORAGE = DEFAULT_FILE_STORAGE COMPRESS_OFFLINE = True