Reputation: 13
Here's my S3 configurations:
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME')
AWS_QUERYSTRING_AUTH = False
I have a couple of models that have ImageFields and when I upload an image it properly gets uploaded to my S3 bucket.
But I also want to put my staticfiles there (JS, CSS). I have manually created a folder in the root of my S3 bucket called static and I have uploaded all of my CSS, JS files to that folder using S3's web app.
However, in my template I am simply doing {% static 'css/main.css' %} and the file is not getting loaded.
I used Chrome's inspect tool to check which resources are being loaded and I think it gets connected to my S3 bucket, but brings the file I want empty, so it is not getting loaded for some reason.
Upvotes: 0
Views: 749
Reputation: 61
You will have to double check that you setup a bucket policy on your S3 bucket allowing public read on the objects and also have to turn off Block public access on the permission tab. By default your Bucket is private with no public access, which means your web app cannot see it. If that is already setup, you will have to check and enable CORS, because Django is trying to access your static files from another domain
Upvotes: 2