Joseph Rajchwald
Joseph Rajchwald

Reputation: 487

collectstatic yielding the error No file or directory : '/app/static' despite having that directory present

I am trying to deploy a django app via Heroku. Initially I was getting errors on deployment and set heroku config:set DISABLE_COLLECTSTATIC=1. Once collectstatic was disabled the app deployed without errors. Now that I want to add my static files I unset heroku config:unset DISABLE_COLLECTSTATIC and tried deploying again but received errors saying my push was rejected. Here is what I believe is the relevant portion of the traceback:

FileNotFoundError: [Errno 2] No such file or directory:'/tmp/build_7f46d0854acc9adac5d065056bd2bc4f/s

Error while running '$ python manage.py collectstatic --noinput'.

My next step was to run heroku run python manage.py collectstatic to get a more accurate traceback and then I received the following error:

FileNotFoundError: [Errno 2] No such file or directory: '/app/static'

This step puzzles me because I have exactly that directory in my app:

lang_site
-- __psyache__
-- static
---- lang_site
------ pic.jpg
------ style.css
-- __init__.py
-- settings.py
-- urls.py
-- views.py
-- wsgi.py

As a shot in the dark I added the literal directory app/static/ in the same directory as settings.py only to yield the same error.

I also added the extra static_dir and static_root lines in my settings.py as seen below:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'

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

Can anyone recommend some next steps?

EDIT: as recommended, I removed the second call to os.path.dirname in my BASE_DIR variable and reran collectstatics. This time I received the following message:

You have requested to collect static files at the destination
location as specified in your settings:

    /app/lang_site/staticfiles

This will overwrite existing files!
Are you sure you want to do this?

I don't have an exact directory with those names. Can anyone help me understand this?

Upvotes: 0

Views: 94

Answers (1)

Akhil S
Akhil S

Reputation: 1171

Create static folder under the root directory that is where all your app resides. Not in the directory where settings.py resides.

Upvotes: 1

Related Questions