我想在heroku上使用django-pipeline和django-storage作为个人应用。仅使用django-pipeline工作得很完美,只使用django-storage就像魅力一样,但我无法让它们同时协同工作:(
当你阅读文档时,你会发现这两个文件都可以使用collecstatic:
Django的管道
settings.py
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
PIPELINE_CSS = {
'app': {
'source_filenames': (
'css/*',
),
'output_filename': 'css/min.css',
'variant': 'datauri',
},
}
Django的存储
settings.py
STATICFILES_STORAGE = 's3storages.StaticStorage'
s3storages.py
from storages.backends.s3boto import S3BotoStorage
StaticStorage = lambda: S3BotoStorage(
bucket='app_name',
location='assets'
)
所以这两个app都需要设置STATICFILE_STORAGE;当我为亚马逊s3设置存储空间时; django-pipeline不会创建min.css和min.js ......
所以我找到this solution on stack并做了以下事情:
from staticfiles.storage import CachedFilesMixin
from pipeline.storage import PipelineMixin
from storages.backends.s3boto import S3BotoStorage
class S3PipelineStorage(PipelineMixin, CachedFilesMixin, S3BotoStorage):
pass
# Define bucket and folder for static files.
StaticStorage = lambda: S3BotoStorage(
bucket='app_name',
location='assets'
)
现在,每次我使用collectstatic命令时,静态文件都会被发送到amazon S3,但django-pipeline min.css和min.js都没有被发送......我的STATIC_ROOT目录中也没有它们的痕迹......
你知道我怎么能一起使用吗?
编辑1:
现在我有了这个:(我改变了s3storage :))
settings.py
STATICFILES_STORAGE = 's3storages.StaticStorage'
s3storage.py
from staticfiles.storage import CachedFilesMixin
from pipeline.storage import PipelineMixin
from storages.backends.s3boto import S3BotoStorage
class S3PipelineStorage(PipelineMixin, CachedFilesMixin, S3BotoStorage):
pass
# Define bucket and folder for static files.
StaticStorage = lambda: S3PipelineStorage(
bucket='app_name',
location='assets'
)
答案 0 :(得分:1)
将STATICFILES_STORAGE
设置为:s3storage.S3PipelineStorage
。
使用settings.AWS_STORAGE_BUCKET_NAME
和settings.AWS_LOCATION
配置S3。