Django存储和django管道 - 仅上传压缩的静态文件

时间:2013-12-08 20:31:58

标签: python django amazon-s3 storage asset-pipeline

我正在尝试将django管道和django-storages结合起来,自动只将压缩文件上传到亚马逊s3。

它总是失败。它正在上传所有可能的文件,或者正在上传空文件,甚至在启用CachedFileFinder时出现错误。

我有点卡住,不知道该做什么。

custom_storages.py

# -*- coding: utf-8 -*-

from django.contrib.staticfiles.storage import CachedFilesMixin
from pipeline.storage import PipelineMixin, PipelineCachedStorage
from storages.backends.s3 import S3Storage
from storages.backends.s3boto import S3BotoStorage

class S3PipelineStorage(PipelineMixin, CachedFilesMixin, S3BotoStorage):
    pass

settings.py

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'django.contrib.admindocs',
    'django.contrib.webdesign',
    'django.contrib.humanize',
    'django.contrib.sitemaps',
    'django.contrib.flatpages',

    # External libs
    'storages',
    'pipeline',
    'endless_pagination',
    'easy_thumbnails',
    'mptt',
    'south',
    #'debug_toolbar',
    'rest_framework',
    'memcache_status',
    'parsley',
    'crispy_forms',
    'crispy_forms_foundation',

    # Apps
    'core',
    'adverts',
    'places',
    'images',
    'categories',
)


DEFAULT_FILE_STORAGE = 'storages.backends.s3.S3Storage'
STATICFILES_STORAGE = 'core.core_storage.S3PipelineStorage'


MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')
MEDIA_URL = '/media/'
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static_root')

STATICFILES_DIRS = (
    os.path.join(PROJECT_DIR, 'static'),
)

STATICFILES_FINDERS = (
    'pipeline.finders.AppDirectoriesFinder',
    'pipeline.finders.FileSystemFinder',
    'pipeline.finders.PipelineFinder',
    #'pipeline.finders.CachedFileFinder',
)


PIPELINE_CSS = {
    'base': {
        'source_filenames': (
            'css/style.css',
        ),
        'output_filename': 'css/core.css',
    },

}

PIPELINE_JS = {
    'base': {
        'source_filenames': (
            'js/libs/jquery-1.10.2.js',
            'foundation/bower_components/foundation/js/foundation.js',
            'foundation/js/app.js',
            'js/jquery.wookmark.js',
            'js/libs/endless-pagination.js',
            'js/libs/jquery.autosize-min.js',
            'js/libs/global.js',
        ),
        'output_filename': 'js/jquery.js',
    },
}

1 个答案:

答案 0 :(得分:0)

CachedFileFinder的错误非常正常,特别是如果使用第三方CSS,因为它试图解析CSS @include语句并将URL转换为缓存版本。你必须非常小心CSS包含的格式。

Django还需要上传所有文件,甚至是未压缩文件,因为它们仍然可能被其中的非缓存名称引用。从理论上讲,你可以摆脱这种限制,但与它一起生活可能会更容易。