简体   繁体   English

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

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

I'm using django-compress to pre-compress my js and css, which are stored in Amazon S3, using the manage.py compress command. 我正在使用django-compress使用manage.py compress命令预压缩存储在Amazon S3中的js和css。

However the issue is that the relative img URLs inside my css are not being replaced with absolute URLs. 但是,问题是我的CSS内的相对img URL未被绝对URL取代。

So I have an image url in css like 所以我在css中有一个图像网址

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

which is not being properly replaced with the absolute S3 URL for the image after running the compress command. 运行compress命令后,该文件未正确替换为映像的绝对S3 URL。 Instead of becoming something like 而不是变成像

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

it stays as 它保持为

"../img/image1.png"

in the compressed css. 在压缩的CSS中。

My django-compress settings in settings.py are the following: 我在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

Solved: I had to add 解决:我必须添加

'compressor.filters.css_default.CssAbsoluteFilter'

to COMPRESS_CSS_FILTERS. 到COMPRESS_CSS_FILTERS。

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

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