[Answer]-Heroku django collectstatic error

1👍

I suspect your getting that error because your BASE_DIR is not setup correctly for your project structure. Try running python manage.py collectstatic --noinput locally to see if you get the same error. You can also print(BASE_DIR) in settings.py to check if it’s pointing to the correct location, and that the static folder is actually in that directory. For my projects, I have the settings file several levels deep, but the static directory is at the root of the project, so my settings look like this:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) // base_dir/subdir/settings/settings.py
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'), // base_dir/static
)

Also, for my Heroku apps, I join BASE_DIR and staticfiles together for STATIC_ROOT like this:

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

On another note, I should warn you that you cannot upload media files directly to your Heroku app like you currently have setup with MEDIA_ROOT. Heroku uses an ephemeral filesystem that discards files you write to it after the dyno is stopped or restarted. You’ll need to use a 3rd party service like Amazon S3 to upload user submitted media files. The django-storages app can help with the integration.

0👍

I might not be able to answer why it is looking at /app/CTFdj/static, but one possible reason is because your STATIC_ROOT might have been configured wrongly. It should be the absolute path where the collected static will be copied to. Have a look at how I normally organize my STATIC_ROOT. Hope this helps.

👤Yeo

Leave a comment