简体   繁体   English

django procfile找不到settings.py

[英]django procfile can't find settings.py

I'm using heroku and django / vertualenv ... I used this boostrap file: https://github.com/mtigas/heroku-django-demo-app/blob/master/tldr.markdown , named my app contest2 but when I try to run foreman locally with foreman start I get: 我正在使用heroku和django / vertualenv ...我使用了这个boostrap文件: https//github.com/mtigas/heroku-django-demo-app/blob/master/tldr.markdown ,命名为我的app contest2但是当我尝试在foreman start在本地运行工头我得到:

raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
11:10:06 web.1     | ImportError: Could not import settings 'src/contest2/contest2/settings.py' (Is it on sys.path?): Import by filename is not supported.

From the dir the procfile is in, this path: src/contest2/contest2/settings.py is correct. 从目录中的proc文件,这个路径: src/contest2/contest2/settings.py是正确的。

My procfile looks like this: 我的procfile看起来像这样:

web: gunicorn_django -b 0.0.0.0:$PORT -w 9 -k gevent --max-requests 250 --preload src/$PYTHON_APP_NAME/$PYTHON_APP_NAME/settings.py > Procfile 

Thanks for your help in advance. 感谢您的帮助。

Your src/contest2/contest2/settings.py is fed to the __import__ function. 你的src/contest2/contest2/settings.py被送到__import__函数。

You can try to simulate the error: 您可以尝试模拟错误:

>>> __import__('path/module.py')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: Import by filename is not supported.
>>>

You probably want to change that to have the python module name and not the path. 您可能希望将其更改为具有python模块名称而不是路径。

The easier way would be to make sure that src/$PYTHON_APP_NAME/$PYTHON_APP_NAME/ is on your path, and just use settings as module name. 更简单的方法是确保路径上有src/$PYTHON_APP_NAME/$PYTHON_APP_NAME/ ,并将settings用作模块名称。

You might want to have a look at the source of the gunicorn_django command to figure out how this works: 您可能希望查看gunicorn_django命令的源代码以了解其工作原理:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM