[Answer]-Django static file URLS are broken

1👍

I found a fix in this git repo. My s3utils.py file now looks like

#s3utils.py
from storages.backends.s3boto import S3BotoStorage
import  os

STATIC_ROOT = 'FOLDER/static'
MEDIA_ROOT = 'FOLDER/media'

class FixedS3BotoStorage(S3BotoStorage):
    def url(self, name):
        url = super(FixedS3BotoStorage, self).url(name)
        if name.endswith('/') and not url.endswith('/'):
            url += '/'
        return url

StaticRootS3BotoStorage = lambda: FixedS3BotoStorage(location=STATIC_ROOT)
MediaRootS3BotoStorage  = lambda: FixedS3BotoStorage(location=MEDIA_ROOT)
👤datinc

0👍

AWS_QUERYSTRING_AUTH = False
AWS_ACCESS_KEY_ID = os.environ.get('your_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('your_key')
AWS_STORAGE_BUCKET_NAME = 'yourbucketname'
AWS_PRELOAD_METADATA = True #helps collectstatic do updates

STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

STATIC_URL = 'https://' + AWS_STORAGE_BUCKET_NAME + '.s3.amazonaws.com/bucket/folder/static'

MEDIA_URL = 'https://' + AWS_STORAGE_BUCKET_NAME + '.s3.amazonaws.com/ bucket/folder/media'

Leave a comment