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?

4

3 回答 3

55

它正在寻找一个名为“static”的文件夹,它位于 settings.py 旁边,即在项目文件夹中,而不是在 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

请注意,git 不会跟踪空文件夹,因此如果它是空的,则必须在其中放置一个空白文件。或者,删除STATICFILES_DIRS设置,直到您需要它为止。

于 2013-10-11T17:19:56.250 回答
17

我刚刚遇到了同样的问题,这是对我有用的解决方案:

我变了:

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

至:

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'myappfolder/static'),
)
于 2014-11-08T03:35:54.837 回答
1

@joerick 上面的答案就是问题。但是,如果您不想放置另一个“静态”文件夹(git root/{your app}/static),您可以考虑更改最初由 django-admin makeproject 提供的 BASE_DIR 变量:

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

这只是 (git root/) 目录

于 2015-11-26T15:34:06.370 回答