簡體   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