如何使Djangostorage和Djangopline一起工作

2024-06-26 13:36:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在heroku上同时使用django管道和django存储作为个人应用程序。只使用django管道工作得很好,只使用django存储就像一个魅力,但我没能让它们两者协同工作:(

当你阅读文档时,你会发现这两种方法都适用于collecstatic:

Django管道:

settings.py
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
PIPELINE_CSS = {
'app': {
    'source_filenames': (
        'css/*',
    ),
    'output_filename': 'css/min.css',
    'variant': 'datauri',
},
}

Django存储

^{pr2}$

所以这两个应用程序都需要设置STATICFILE_存储;当我为amazons3设置存储时,django管道不会创建最小.css以及最小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命令时,静态文件都被发送到amazons3,但是django管道最小.css以及最小js不发送。。。在我的静态根目录中也没有它们的踪迹。。。。在

你知道我怎么把两者都用在一起吗?在

编辑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'
)

Tags: djangofrompyimportapp管道pipelinebucket