0

I am trying to push my Django + React app to heroku. I have configured the path for my static files at below in settings.py

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'laundryman_frontend/build/static')
]

The build is successful when I push to heroku but when I run heroku run python manage.py collectstatic I get the error FileNotFoundError: [Errno 2] No such file or directory: '/app/laundryman_frontend/build/static'

this is what BASE_DIR is set to: BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

My guess is that, Heroku is not looking does not recognise the path that I have set for the static files.

Kindly help me solve this issue

1 Answers1

0

The logic of the code snippets in your question is very simple.

  1. Set BASE_DIR to the directory that contains the manage.py file.

    BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    
  2. Set the STATICFILES_DIRS relative to the BASE_DIR.

    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, 'app/laundryman_frontend/build/static')
    ]
    

If that "algorithm" doesn't work (i.e. your Django app's static files directory is set incorrectly) then:

  • manage.py is in the wrong place, or
  • the relative path you provided is incorrect, or (maybe)
  • some stuff hasn't been deployed.

I guess it is also possible that collectstatic didn't work; see https://devcenter.heroku.com/articles/django-assets

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • I have tried everything but it is stiil not working. Heroku keeps looking at ```"app/laundryman_frontend/build/static"``` meanwhile I have set STATICFILES_DIRS to ```os.path.join(BASE_DIR, 'laundryman_frontend/build/static')``` I dont know why heroku preceedes the path with "app". – Khal Shaphat Aug 01 '22 at 10:38