How to configure django-compressor and django-staticfiles with Amazon's S3?

前端 未结 4 1703
遇见更好的自我
遇见更好的自我 2021-02-01 03:51

I\'m trying to setup django-compressor and django-staticfiles so that the compressed CSS/Javascript and images are served from Amazon\'s S3.

I\'ve managed to setup stati

4条回答
  •  不思量自难忘°
    2021-02-01 04:32

    Your settings look correct. You should keep both STATICFILES_STORAGE and COMPRESS_STORAGE set to storage.CachedS3BotoStorage though and not switch back to storages.backends.s3boto.S3BotoStorage.

    According to this django-compressor issue, the problem is with the way django-staticfiles saves during the collectstatic process (using shutil.copy2). This issue has been corrected in the newer version of django-staticfiles, which can be used instead of the one that ships with Django 1.3.

    pip install django-staticfiles==dev
    

    And in your settings.py, switch to the updated version:

    STATICFILES_FINDERS = (
        #"django.contrib.staticfiles.finders.FileSystemFinder",
        #"django.contrib.staticfiles.finders.AppDirectoriesFinder",
        "staticfiles.finders.FileSystemFinder",
        "staticfiles.finders.AppDirectoriesFinder",
        "compressor.finders.CompressorFinder",
    )
    
    INSTALLED_APPS = (
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        #'django.contrib.staticfiles',
        'staticfiles',
        #...
    )
    

    After running python manage.py collectstatic again, both the CACHE directory from django-compressor and the collected staticfiles files should show up on S3.

提交回复
热议问题