简体   繁体   English

Django Gunicorn:无法找到应用程序

[英]Django Gunicorn: Unable to find application

I started with a fresh install of django into a Python 3.4 virtualenv. 我开始将全新安装的django安装到Python 3.4 virtualenv中。 I then tried to start gunicorn following a tutorial to test on the first ever run and it fails. 然后,我尝试在第一次运行的测试教程后启动gunicorn,但它失败了。 I have a fully configured development server in which gunicorn fails to run showing me the same error that there is no module named <django project name>.wsgi . 我有一个完全配置的开发服务器,其中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'

The only reason I started a new server to test this new Django project is in the hopes that gunicorn will work thinking I might have misconfigured something on my old dev server. 我开始使用新服务器来测试这个新的Django项目的唯一原因是希望gunicorn会认为我可能在我的旧开发服务器上配置错误。 Keep in mind that this is completely fresh. 请记住,这是完全新鲜的。 I have touched nothing in the Django project folder or settings.py except for configuring the database. 除了配置数据库之外,我没有在Django项目文件夹或settings.py触及任何内容。

EDIT: Added file structure. 编辑:添加了文件结构。

(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

The gunicorn command is being executed from test_project folder. gunicorn命令正在从test_project文件夹中执行。

(test_projectprodenv)djangouser@ff:~$ which gunicorn
/home/djangouser/test_projectprodenv/bin/gunicorn

If your application is not installed in the Python environment along with Gunicorn, you have to add it on the Python path, so that Gunicorn can see it, either by running from where the package is located or by specifying that location via the --pythonpath STRING command line option. 如果您的应用程序未与Gunicorn一起安装在Python环境中,则必须将其添加到Python路径中,以便Gunicorn可以通过从程序包所在位置运行或通过--pythonpath STRING指定该位置来--pythonpath STRING命令行选项。

So either start the server from ~/test_project : 所以要么从~/test_project启动服务器:

~/test_project$ gunicorn test_project.wsgi:application --bind 162.243.195.141:8001

or with --pythonpath option from your home directory: 或者使用主目录中的--pythonpath选项:

~$ gunicorn test_project.wsgi:application --pythonpath test_project --bind 162.243.195.141:8001

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

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