我使用manage.py compress命令,使用django-compress对存储在亚马逊S3中的js和css进行预压缩。
然而,问题是我的css中的相对img URL没有被绝对URL替换。
所以我有一个css格式的图像url,比如
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发布于 2014-11-21 07:18:53
解决方法:我不得不添加
'compressor.filters.css_default.CssAbsoluteFilter'敬COMPRESS_CSS_FILTERS。
https://stackoverflow.com/questions/27039797
复制相似问题