【问题标题】:Configuring django-compressor with remote storage (django-storage - amazon s3)使用远程存储配置 django-compressor (django-storage - amazon s3)
【发布时间】: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


    【解决方案1】:

    我认为您缺少的唯一设置是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
    

    【讨论】:

    • 是的,不知道为什么,但是如果您错过了 COMPRESS_ROOT 设置,它不会按预期运行。很奇怪,但感谢@bradenm 证实了我的怀疑。
    • 这拯救了我的一天
    猜你喜欢
    • 2017-07-29
    • 2015-04-05
    • 2014-04-24
    • 2018-07-08
    • 2015-10-05
    • 2020-12-13
    • 2022-01-17
    • 2016-03-14
    • 2021-10-28
    相关资源
    最近更新 更多