django-compress not replacing relative urls in css with absolute urls

555 Views Asked by At

I'm using django-compress to pre-compress my js and css, which are stored in Amazon S3, using the manage.py compress command.

However the issue is that the relative img URLs inside my css are not being replaced with absolute URLs.

So I have an image url in css like

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. Instead of becoming something like

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

it stays as

"../img/image1.png"

in the compressed css.

My django-compress settings in settings.py are the following:

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
1

There are 1 best solutions below

0
On

Solved: I had to add

'compressor.filters.css_default.CssAbsoluteFilter'

to COMPRESS_CSS_FILTERS.