[英]Django Gunicorn: Unable to find application
我开始将全新安装的django安装到Python 3.4 virtualenv中。 然后,我尝试在第一次运行的测试教程后启动gunicorn,但它失败了。 我有一个完全配置的开发服务器,其中gunicorn无法运行,向我显示相同的错误,没有名为<django project name>.wsgi
模块。
(test_projectprodenv)djangouser@ff:~$ gunicorn test_project.wsgi:application --bind 162.243.195.141:8001
Exception in worker process:
Traceback (most recent call last):
File "/home/djangouser/test_projectprodenv/lib/python3.4/site-packages/gunicorn/arbiter.py", line 502, in spawn_worker
worker.init_process()
File "/home/djangouser/test_projectprodenv/lib/python3.4/site-packages/gunicorn/workers/base.py", line 114, in init_process
self.wsgi = self.app.wsgi()
File "/home/djangouser/test_projectprodenv/lib/python3.4/site-packages/gunicorn/app/base.py", line 66, in wsgi
self.callable = self.load()
File "/home/djangouser/test_projectprodenv/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/home/djangouser/test_projectprodenv/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/home/djangouser/test_projectprodenv/lib/python3.4/site-packages/gunicorn/util.py", line 356, in import_app
__import__(module)
ImportError: No module named 'test_project.wsgi'
我开始使用新服务器来测试这个新的Django项目的唯一原因是希望gunicorn会认为我可能在我的旧开发服务器上配置错误。 请记住,这是完全新鲜的。 除了配置数据库之外,我没有在Django项目文件夹或settings.py
触及任何内容。
编辑:添加了文件结构。
(test_projectprodenv)djangouser@ff:~$ ls
test_project test_projectprodenv
(test_projectprodenv)djangouser@ff:~/test_project$ tree
.
├── test_project
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-34.pyc
│ │ ├── settings.cpython-34.pyc
│ │ ├── urls.cpython-34.pyc
│ │ └── wsgi.cpython-34.pyc
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── manage.py
2 directories, 9 files
gunicorn
命令正在从test_project文件夹中执行。
(test_projectprodenv)djangouser@ff:~$ which gunicorn
/home/djangouser/test_projectprodenv/bin/gunicorn
如果您的应用程序未与Gunicorn一起安装在Python环境中,则必须将其添加到Python路径中,以便Gunicorn可以通过从程序包所在位置运行或通过--pythonpath STRING
指定该位置来--pythonpath STRING
命令行选项。
所以要么从~/test_project
启动服务器:
~/test_project$ gunicorn test_project.wsgi:application --bind 162.243.195.141:8001
或者使用主目录中的--pythonpath
选项:
~$ gunicorn test_project.wsgi:application --pythonpath test_project --bind 162.243.195.141:8001
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.