I currently have DigitalOcean spaces setup & using it with django via ‘django-storages’.
Currently I am running into a problem where the collectstatic command will not collect all my static files.
settings.py - static files
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
AWS_ACCESS_KEY_ID = 'my_access_key'
AWS_SECRET_ACCESS_KEY = 'my_secret_key'
AWS_STORAGE_BUCKET_NAME = 'lrev'
AWS_S3_ENDPOINT_URL = 'https://fra1.digitaloceanspaces.com'
AWS_S3_OBJECT_PARAMETERS = {
'CacheControl': 'max-age=86400',
}
STATICFILES_STORAGE = 'custom_storages.StaticStorage'
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'
# Use AWS_S3_ENDPOINT_URL here if you haven't enabled the CDN and got a custom domain.
STATIC_URL = '{}/{}/'.format(AWS_S3_ENDPOINT_URL, 'static')
STATIC_ROOT = '/static/'
MEDIA_URL = '{}/{}/'.format(AWS_S3_ENDPOINT_URL, 'media')
MEDIA_ROOT = '/media/'
TEMP = "{}/{}".format(MEDIA_ROOT, 'temp')
My Static Files:
static
- accounts
- core
- images
- lrdc
- terms
- jquery.js
Digital Ocean Spaces:
static
- images
- images
- admin
- jquery.js
Any help will be greatly appreciated! Thank you :D
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.
Heya,
It seems like you’re experiencing issues with the
collectstatic
command not gathering all of your static files in your Django project. Let’s break down the potential issues and solutions:Verify that
collectstatic
is working properly: First, run thecollectstatic
command manually in your local environment and see if it is collecting all the static files. If it’s not, the issue might not be related to DigitalOcean spaces, but with how your static files are set up.Check your
custom_storages.py
module: You’re usingcustom_storages.StaticStorage
andcustom_storages.MediaStorage
as yourSTATICFILES_STORAGE
andDEFAULT_FILE_STORAGE
respectively. It’s possible that these classes might be incorrectly defined, causing issues. It would be helpful to review those classes.Confirm your static files location: Make sure all static files are properly placed under the directories specified in the
STATICFILES_DIRS
setting. From your file structure, it seems like you’ve got your static files correctly placed. But it might be worth double checking if all files are under the ‘static’ directory in yourBASE_DIR
.STATIC_ROOT Setting:
STATIC_ROOT
is the absolute path to the directory wherecollectstatic
will collect static files for deployment. In your configuration, it seems like you’re setting it to ‘/static/’. Please ensure that this directory is correctly set and Django has appropriate permissions to access and write into this directory.STATICFILES_FINDERS Setting: Django uses the
STATICFILES_FINDERS
setting to locate static files in addition to those it finds inSTATICFILES_DIRS
. By default, it includesFileSystemFinder
(for files inSTATICFILES_DIRS
) andAppDirectoriesFinder
(for files in the ‘static’ subdirectory of each app). If you haven’t changed this setting, Django should automatically find static files in your apps. However, if you’ve changed it, that might be causing your problem.Bucket Policy: Please ensure that your bucket policy in DigitalOcean Spaces is set correctly. You should have read and write permissions for the provided AWS key and secret.
Hopefully, one of these points will help you identify the issue. If none of these work, please provide any error messages you’re getting, or any other unusual behavior you’re seeing when you run
collectstatic
.