1

我正在使用 django-compress 使用 manage.py compress 命令预压缩存储在 Amazon S3 中的 js 和 css。

但是问题是我的 css 中的相对 img URL 没有被绝对 URL 替换。

所以我在css中有一个图片网址,比如

background-image:url("../img/image1.png")

在运行 compress 命令后,它没有被正确地替换为图像的绝对 S3 URL。而不是变成类似的东西

https://webappbucket.s3.amazon.com/img/image1.png 

它保持不变

"../img/image1.png"

在压缩的 CSS 中。

我在 settings.py 中的 django-compress 设置如下:

STATICFILES_DIRS = (
    'webapp/static',
)

INSTALLED_APPS += ('storages',)

STATICFILES_STORAGE = 'lib.storage.CachedS3BotoStorage'

AWS_ACCESS_KEY_ID = constants.AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY = constants.AWS_SECRET_ACCESS_KEY
AWS_STORAGE_BUCKET_NAME = constants.S3_BUCKET_NAME
S3_URL = 'https://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME
STATIC_URL = S3_URL

#compress
COMPRESS = True
COMPRESS_OFFLINE = True
COMPRESS_ROOT = "../"
COMPRESS_ENABLED = True
COMPRESS_STORAGE = STATICFILES_STORAGE

COMPRESS_JS_FILTERS = [
    'lib.compressor_filters.YUglifyJSFilter',
]

COMPRESS_CSS_FILTERS = [
    'lib.compressor_filters.YUglifyCSSFilter',
]

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    # other finders..
    'compressor.finders.CompressorFinder',
)

COMPRESS_YUGLIFY_BINARY = 'node_modules/yuglify/bin/yuglify' # assumes yuglify is in your path
COMPRESS_YUGLIFY_CSS_ARGUMENTS = '--terminal'
COMPRESS_YUGLIFY_JS_ARGUMENTS = '--terminal'

COMPRESS_URL = STATIC_URL

STATIC_ROOT = "../"

AWS_QUERYSTRING_AUTH = False
4

1 回答 1

0

已解决:我必须添加

'compressor.filters.css_default.CssAbsoluteFilter'

到 COMPRESS_CSS_FILTERS。

于 2014-11-20T23:18:53.167 回答