settings.py:


      "myproject"/staticfiles/"media_imports_file_folder"

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

      "myproject"/mediafiles/"media_imports_file_folder"

      MEDIA_URL = /mediafiles/'
      MEDIA_ROOT = os.path.join(BASE_DIR, 'mediafiles')''
      

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

Storing Django Files in S3

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_DIRS = (os.path.join(BASE_DIR, 'static'),)

MEDIA_URL = '/mediafiles/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'mediafiles')