Django collectstatic does not update modified files in s3

1

I'm using Django 1.10.6 , followed this tutorial to set up media and staticfiles on s3 and when squeeze collectstatic , files are not updated. p>     

asked by anonymous 16.05.2017 / 17:56

2 answers

2

I've created a settings file to run collectstatic locally to sync with s3. In this file I set:

TIME_ZONE = 'UTC'

It worked perfectly.

I'm using S3 in São Paulo, theoretically the S3 timezone is the same as my location and should work correctly. But it did not work. I think the timezone it shows on the S3 console is different from the actual timezone of the files.

    
16.05.2017 / 17:58
1

Okay, you even answered your question (before I see it, ehehe!), but I can not help but add my answer, even to, also, document. After having several problems with static files, on several servers (each in a different way), I found a solution, which, to me, seems magical.Chama Whitenoise, below how to do magic:

1) Install Whitenoise:

pip install whitenoise

2) Edit your settings.py and add Whitenoise to the MIDDLEWARE_CLASSES list above all others, from Django's SecurityMiddleware:

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
     ....
]

3) To support understanding of files and cache, add to settings.py :

 STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

Below is a summary (of a real case) of what is important to have in the file settings.py , in addition to the one mentioned in item 2.

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
....

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'

# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT, 'static'),
)

# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

//whitenoise.evans.io/en/stable/django.html"> topic dedicated to django , including instructions for Amazon CloudFront.

Project website

    
17.05.2017 / 16:45