我试图用部署在Heroku上gunicorn一个Django应用程序,我碰到几个提高警惕。
当我开始我的项目我的Django的版本是1.3,不包含标准wsgi.py模块,所以我增加了标准WSGI模块顶部/ wsgi.py(顶部是我的项目名称,土耳其人是我的应用程序名称,topturk是其所包含的目录 - 保留,这样的错误日志进行以下意义上的)。
现在,当我运行
gunicorn top.wsgi:application -b 0.0.0.0:$PORT
服务器已成功启动,
19:00:42 web.1 | started with pid 7869
19:00:42 web.1 | 2012-07-25 19:00:42 [7869] [INFO] Starting gunicorn 0.14.5
19:00:42 web.1 | 2012-07-25 19:00:42 [7869] [INFO] Listening at: http://0.0.0.0:5000 (7869)
19:00:42 web.1 | 2012-07-25 19:00:42 [7869] [INFO] Using worker: sync
19:00:42 web.1 | 2012-07-25 19:00:42 [7870] [INFO] Booting worker with pid: 7870
但后来当我浏览到0.0.0.0:5000我得到返回的内部服务器错误:
19:00:45 web.1 | 2012-07-25 17:00:45 [7870] [ERROR] Error handling request
19:00:45 web.1 | Traceback (most recent call last):
19:00:45 web.1 | File "/Users/intenex/Dropbox/code/django/topturk/venv/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 102, in handle_request
19:00:45 web.1 | respiter = self.wsgi(environ, resp.start_response)
19:00:45 web.1 | File "/Users/intenex/Dropbox/code/django/topturk/venv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 219, in __call__
19:00:45 web.1 | self.load_middleware()
19:00:45 web.1 | File "/Users/intenex/Dropbox/code/django/topturk/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 47, in load_middleware
19:00:45 web.1 | raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
19:00:45 web.1 | ImproperlyConfigured: Error importing middleware turk.middleware.subdomain: "No module named turk.middleware.subdomain"
19:00:47 web.1 | 2012-07-25 17:00:47 [7870] [ERROR] Error handling request
19:00:47 web.1 | Traceback (most recent call last):
19:00:47 web.1 | File "/Users/intenex/Dropbox/code/django/topturk/venv/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 102, in handle_request
19:00:47 web.1 | respiter = self.wsgi(environ, resp.start_response)
19:00:47 web.1 | File "/Users/intenex/Dropbox/code/django/topturk/venv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 219, in __call__
19:00:47 web.1 | self.load_middleware()
19:00:47 web.1 | File "/Users/intenex/Dropbox/code/django/topturk/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 47, in load_middleware
19:00:47 web.1 | raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
19:00:47 web.1 | ImproperlyConfigured: Error importing middleware turk.middleware.subdomain: "No module named turk.middleware.subdomain"
我假设这是一个Python路径误差,其中,服务器不知道如何从我的应用程序目录中导入
有关进口的代码是在这里设置:
MIDDLEWARE_CLASSES = (
'turk.middleware.subdomain.SubdomainMiddleware',
'turk.middleware.removewww.RemoveWWWMiddleware',
)
我试图通过我的settings.py文件中,像这样的顶部插入我的应用程序目录到sys.path中像这样来解决这个问题:
PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(1, PROJECT_ROOT+'/turk/')
我已经验证了添加应用程序目录的路径,但仍然没有骰子。 有任何想法吗? 也
sys.path.insert(1, PROJECT_ROOT+'/turk/')
似乎hackish的,并增加了目录的至少两个拷贝的路径,什么是追加到PYTHON_PATH在Django正确的方法是什么? 谢谢!