繁体   English   中英

django-compress不使用绝对URL替换CSS中的相对URL

[英]django-compress not replacing relative urls in css with absolute urls

我正在使用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

解决:我必须添加

'compressor.filters.css_default.CssAbsoluteFilter'

到COMPRESS_CSS_FILTERS。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM