Report this

What is the reason for this report?

python manage.py collectstatic does not copy all my static files

Posted on October 21, 2022
Goto baileyq.me

By Goto baileyq.me

Student

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.

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:

  1. Verify that collectstatic is working properly: First, run the collectstatic 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.

  2. Check your custom_storages.py module: You’re using custom_storages.StaticStorage and custom_storages.MediaStorage as your STATICFILES_STORAGE and DEFAULT_FILE_STORAGE respectively. It’s possible that these classes might be incorrectly defined, causing issues. It would be helpful to review those classes.

  3. 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 your BASE_DIR.

  4. STATIC_ROOT Setting: STATIC_ROOT is the absolute path to the directory where collectstatic 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.

  5. STATICFILES_FINDERS Setting: Django uses the STATICFILES_FINDERS setting to locate static files in addition to those it finds in STATICFILES_DIRS. By default, it includes FileSystemFinder (for files in STATICFILES_DIRS) and AppDirectoriesFinder (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.

  6. 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.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.