我正在使用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
答案 0 :(得分:0)
解决:我必须添加
'compressor.filters.css_default.CssAbsoluteFilter'
到COMPRESS_CSS_FILTERS。