Heroku& Django:“OSError:没有这样的文件或目录:'/ app / {myappname} / static'” [英] Heroku & Django: "OSError: No such file or directory: '/app/{myappname}/static'"

查看:153
本文介绍了Heroku& Django:“OSError:没有这样的文件或目录:'/ app / {myappname} / static'”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Heroku上有一个Django应用程序。我对静态文件有一些问题(他们正在加载一个Heroku 环境,而不是另一个),所以我尝试了调试命令推荐 here

  $ heroku运行python manage.py collectstatic --noinput 
运行`python manage.py collectstatic --noinput`附加到终端... up,run.8771
OSError:[Errno 2]没有这样的文件或目录:'/ app / {myappname} / static'

这是我的settings.py,这是Heroku建议的相同的东西:

  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'),

pre>

/ p>

任何一个我都可以得到错误,无论我是否真的有一个目录静态在根级别在我的Git repo想法?

解决方案

正在寻找一个位于settings.py旁边的名为static的文件夹,即在项目文件夹中,不是git repo的根源。

  git root / 
git root / {app name}
git root / {app name} /settings.py
git root / {app name} / static /< - 这是你缺少的

请注意,空文件夹不被git跟踪,因此如果空文件为空,则必须将空文件放在那里。或者,删除 STATICFILES_DIRS 设置,直到需要它。


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?

解决方案

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.

这篇关于Heroku&amp; Django:“OSError:没有这样的文件或目录:'/ app / {myappname} / static'”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆