使用Django 1.5rc(也试过1.4)我试图让CachedStaticFilesStorage与Boto一起工作。
当我在没有Boto的情况下使用CachedStaticFilesStorage时,它可以正常工作:
DEFAULT_FILE_STORAGE = 'django.contrib.staticfiles.storage.CachedStaticFilesStorage'
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.CachedStaticFilesStorage'
STATICFILES_S3_OPTIONS = {
"bucket": "bucket-name"
}
python manage.py collectstatic
Copying '/user/project/static/css/min/styles.min.css'
Copying '/user/project/static/js/min/scripts.min.js'
Post-processed 'styles.min.css' as 'styles.min.694c8cd7e18b.css
Post-processed 'scripts.min.js' as 'scripts.min.1111e876b4f7.js
但是,当我更改存储后端时会发生以下情况:
DEFAULT_FILE_STORAGE = "storages.backends.s3boto.S3BotoStorage"
STATICFILES_STORAGE = "project.storage.CachedStaticS3BotoStorage"
python manage.py collectstatic
Copying '/user/project/static/css/min/styles.min.css'
Copying '/user/project/static/js/min/scripts.min.js'
File "/user/.virtualenvs/project/lib/python2.7/site-packages/boto/s3/bucket.py", line 461, in new_key
raise ValueError('Empty key names are not allowed')
ValueError: Empty key names are not allowed
ValueError: Empty key names are not allowed
这是我的storage.py
from django.conf import settings
from django.contrib.staticfiles.storage import CachedFilesMixin
from storages.backends.s3boto import S3BotoStorage
class CachedStaticS3BotoStorage(CachedFilesMixin, S3BotoStorage):
def __init__(self, *args, **kwargs):
kwargs.update(getattr(settings, "STATICFILES_S3_OPTIONS", {}))
super(CachedStaticS3BotoStorage, self).__init__(*args, **kwargs)