Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django-storages not detecting changed static files

I'm using django-storages and amazon s3 for my static files. Following the documentation, I put these settings in my settings.py

STATIC_URL = 'https://mybucket.s3.amazonaws.com/'

ADMIN_MEDIA_PREFIX = 'https://mybucket.s3.amazonaws.com/admin/'

INSTALLED_APPS += (
    'storages',
)

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_ACCESS_KEY_ID = 'mybucket_key_id'
AWS_SECRET_ACCESS_KEY = 'mybucket_access_key'
AWS_STORAGE_BUCKET_NAME = 'mybucket'
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

And the first time I ran collect static everything worked correctly and my static files were uploaded to my s3 bucket.

However, after making changes to my static files and running python manage.py collectstatic this is outputted despite the fact that static files were modified

-----> Collecting static files
    0 static files copied, 81 unmodified.

However, if I rename the changed static file, the changed static file is correctly copied to my s3 bucket.

Why isn't django-storages uploading my changed static files? Is there a configuration problem or is the problem deeper?

like image 477
bab Avatar asked Jul 06 '13 22:07

bab


2 Answers

collectstatic skips files if "target" file is "younger" than source file. Seems like amazon S3 storage returns wrong date for you file.

you could investigate [code][1] and debug server responses. Maybe there is a problem with timezone.

Or you could just pass --clear argument to collectstatic so that all files are deleted on S3 before collecting

like image 64
imposeren Avatar answered Sep 27 '22 17:09

imposeren


https://github.com/antonagestam/collectfast

From readme.txt : Custom management command that compares the MD5 sum and etag from S3 and if the two are the same skips file copy. This makes running collect static MUCH faster if you are using git as a source control system which updates timestamps.

like image 27
yeaske Avatar answered Sep 27 '22 17:09

yeaske