2

I'm using S3 to store my static files, but I'm having an issue where only the admin static files are uploading to the bucket.

I expected to see the css and other folders from inside static upload to the bucket, but instead, this is all I got:

static/
- admin/
- flags/

What can I do to get my app's static folder to upload also?

Looking at other answers to this question, it seems like the main difference is that my project uses django-sass-processor, but I'm not sure why that would mean my entire folder is not picked up.

Project folder structure:

backend/
- accounts/
- core/
-- settings.py
-- ...
- static/
- templates/

settings.py

USE_S3 = os.getenv('USE_S3') == 'TRUE'

if USE_S3:
    # aws settings
    AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
    AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY')
    AWS_STORAGE_BUCKET_NAME = os.getenv('AWS_STORAGE_BUCKET_NAME')
    AWS_DEFAULT_ACL = 'public-read'
    AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com'
    AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'}
    # s3 static settings
    AWS_LOCATION = 'static'
    STATIC_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/{AWS_LOCATION}/'
    STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
else:
    STATIC_URL = '/staticfiles/'
    STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'sass_processor.finders.CssFinder',
]

SASS_PROCESSOR_ROOT = os.path.join(BASE_DIR, 'static')


STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
2
  • 1
    I think you may be missing 'django.contrib.staticfiles.finders.FileSystemFinder' in STATICFILES_FINDERS. Commented Mar 18, 2022 at 0:04
  • Adding this gives the error 'The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting' Commented Mar 18, 2022 at 17:13

1 Answer 1

0

I've managed to fix python manage.py collectstatic --no-input copying only admin files by replacing STATIC_ROOT variable with STATICFILES_DIRS.

I.e. my previous settings.py was

STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',

]
STATIC_ROOT = BASE_DIR / "static"

And I altered it to

STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
STATIC_ROOT = BASE_DIR / "newStaticRoot",  # just make a new empty dir. 
STATICFILES_DIRS = [BASE_DIR / "static",]

Then doing collectstatic successfully copied all my files to s3 bucket.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.