41

I have a Django app on Heroku. I am having some problems with static files (they are loading in one Heroku environment but not another), so I tried the debug command recommended here.

$ heroku run python manage.py collectstatic --noinput
Running `python manage.py collectstatic --noinput` attached to terminal... up, run.8771
OSError: [Errno 2] No such file or directory: '/app/{myappname}/static'

Here is my settings.py, which is the same thing Heroku recommends:

import os
import os.path

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'

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

I get the error whether or not I actually have a directory "static" at the root level in my Git repo (tested it both ways).

Any ideas?

RexE
  • 17,085
  • 16
  • 58
  • 81

3 Answers3

56

It's looking for a folder named 'static' that's next to the settings.py, i.e. in the project folder, not at the root of the git repo.

git root/
git root/{app name}
git root/{app name}/settings.py
git root/{app name}/static/         <- this is what you're missing

Note that empty folders aren't tracked by git, so you'll have to put a blank file in there if it's empty. Alternatively, remove the STATICFILES_DIRS setting until you need it.

joerick
  • 16,078
  • 4
  • 53
  • 57
  • I had the same problem on a heroku site, and the only thing missing was a blank .gitignore file! – Stein G. Strindhaug Apr 24 '14 at 13:20
  • 2
    Almost nothing worked for me, except the last item "Alternatively, remove the STATICFILES_DIRS setting until you need it" which made everything work beautifully. Heroku would not "collect static" until that line went away. – CoderOfTheNight Aug 27 '15 at 08:56
  • Perfect man, this was the problem I was having. I just couldn't figure out where to put the damn templates. – Amon Dec 19 '18 at 17:08
  • I like the last part of the answer. `...remove the STATICFILES_DIRS setting until you need it.` E.g. One does not really need it in the Development server. – Laenka-Oss Jan 23 '22 at 00:31
17

I just had this same problem, and here's the solution that worked for me:

I changed:

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

to:

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'myappfolder/static'),
)
Michelle Glauser
  • 1,097
  • 16
  • 28
  • 2
    This worked for me as well, although my path required moving up a directory: `os.path.join(BASE_DIR, '../myappfolder/static')` – Joseph Nov 14 '14 at 03:55
  • none of them works for me, it is, "myappfolder " means the name of your app on heroku or just myappfolder – Adil Warsi Jan 30 '19 at 13:41
1

@joerick's answer above is the thing. However, if you do not want to place another 'static' folder (git root/{your app}/static), you might consider changing the BASE_DIR variable that is initially supplied by django-admin makeproject:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

which is just the (git root/) directory

Dima
  • 73
  • 6