配置远程存储的django-compression(django-storage - amazon s3) [英] Configuring django-compressor with remote storage (django-storage - amazon s3)

查看:177
本文介绍了配置远程存储的django-compression(django-storage - amazon s3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用django-storage来通过Amazon S3提供文件。
这意味着当我做./manage.py collectstatic时,这些文件将被保存在我的存储区中,而不是在本地文件系统上。

I'm using django-storage to have the files served via Amazon S3. This means that when I do ./manage.py collectstatic, the files will be saved on my bucket at amazon and not on the local file system.

要压缩我做的文件:./manage.py compress
哪个给出这个错误:

To compress the files I do: "./manage.py compress" Which gives this error:

错误:渲染期间发生错误:[Errno 2 ]没有这样的文件或目录:u'/ home / user / project / static / less / bootstrap.less'

Error: An error occured during rendering: [Errno 2] No such file or directory: u'/home/user/project/static/less/bootstrap.less'

由于文件不在我的本地文件系统上。

Since the file isn't on my local filesystem.

由于Django Compressor处理文件的方式,它需要处理文件(在{%compress%}块中)以可用于本地文件系统缓存。
http://django_compressor.readthedocs.org/en /最新/远程存储/

"Due to the way Django Compressor processes files, it requires the files to be processed (in the {% compress %} block) to be available in a local file system cache." http://django_compressor.readthedocs.org/en/latest/remote-storages/

如何使django-compress工作使用django-storage(amazon s3)?

How do I make django-compress work with django-storage (amazon s3)?

本地和S3上都会保存文件。由于在django-compressor页面的文档中提到,所以应该有一些很好的方法。如何?

Make collectstatic save files both local and on S3. Since it's mentioned mentioned in the documentation at the django-compressor page, there should be some good way to do it. How?

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

I think the only setting you are missing is COMPRESS_ROOT.

我有dja ngo压缩机与S3工作非常好。这是我的配置:

I have django-compressor working very nicely with S3. Here's my configuration:

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

这篇关于配置远程存储的django-compression(django-storage - amazon s3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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