0

我尝试为我的 Django 网站安装和使用 gunicorn,但我遇到了这个错误:

$ python manage.py run_gunicorn
2012-12-19 01:46:50 [6877] [INFO] Starting gunicorn 0.16.1
2012-12-19 01:46:50 [6877] [INFO] Listening at: http://127.0.0.1:8000 (6877)
2012-12-19 01:46:50 [6877] [INFO] Using worker: sync
2012-12-19 01:46:50 [6878] [INFO] Booting worker with pid: 6878
2012-12-19 01:46:51 [6878] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/arbiter.py", line 469, in spawn_worker
    worker.init_process()
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process
    self.wsgi = self.app.wsgi()
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/app/base.py", line 99, in wsgi
    self.callable = self.load()
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/app/djangoapp.py", line 134, in load
    return mod.make_command_wsgi_application(self.admin_media_path)
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 116, in make_command_wsgi_application
    return AdminMediaHandler(make_wsgi_application(), admin_mediapath)
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 36, in make_wsgi_application
    if get_validation_errors(s):
  File "... project folder .../venv/lib/python2.7/site-packages/django/core/management/validation.py", line 35, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "... project folder .../venv/lib/python2.7/site-packages/django/db/models/loading.py", line 146, in get_app_errors
    self._populate()
  File "... project folder .../venv/lib/python2.7/site-packages/django/db/models/loading.py", line 61, in _populate
    self.load_app(app_name, True)
  File "... project folder .../venv/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in load_app
    models = import_module('.models', app_name)
  File "... project folder .../venv/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "... project folder .../venv/lib/python2.7/site-packages/south/models.py", line 2, in <module>
    from south.db import DEFAULT_DB_ALIAS
  File "... project folder .../venv/lib/python2.7/site-packages/south/db/__init__.py", line 81, in <module>
    db = dbs[DEFAULT_DB_ALIAS]
KeyError: 'default'
Traceback (most recent call last):
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/arbiter.py", line 469, in spawn_worker
    worker.init_process()
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process
    self.wsgi = self.app.wsgi()
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/app/base.py", line 99, in wsgi
    self.callable = self.load()
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/app/djangoapp.py", line 134, in load
    return mod.make_command_wsgi_application(self.admin_media_path)
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 116, in make_command_wsgi_application
    return AdminMediaHandler(make_wsgi_application(), admin_mediapath)
  File "... project folder .../venv/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 36, in make_wsgi_application
    if get_validation_errors(s):
  File "... project folder .../venv/lib/python2.7/site-packages/django/core/management/validation.py", line 35, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "... project folder .../venv/lib/python2.7/site-packages/django/db/models/loading.py", line 146, in get_app_errors
    self._populate()
  File "... project folder .../venv/lib/python2.7/site-packages/django/db/models/loading.py", line 61, in _populate
    self.load_app(app_name, True)
  File "... project folder .../venv/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in load_app
    models = import_module('.models', app_name)
  File "... project folder .../venv/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "... project folder .../venv/lib/python2.7/site-packages/south/models.py", line 2, in <module>
    from south.db import DEFAULT_DB_ALIAS
  File "... project folder .../venv/lib/python2.7/site-packages/south/db/__init__.py", line 81, in <module>
    db = dbs[DEFAULT_DB_ALIAS]
KeyError: 'default'
2012-12-19 01:46:51 [6878] [INFO] Worker exiting (pid: 6878)
2012-12-19 01:46:51 [6877] [INFO] Shutting down: Master
2012-12-19 01:46:51 [6877] [INFO] Reason: Worker failed to boot.

我发现这个问题有类似的错误,但我的 DATABASES 字典里面settings.py似乎是正确的:

DATABASES = {
    'default': {
        'ENGINE': 'postgresql_psycopg2',
        ...
    }
}

我已经放入gunicorn我的INSTALLED_APPS. runserver工作得很好。south似乎它本身也能很好地工作。

我设法通过south在我的INSTALLED_APPS. 我想当我部署到生产环境时可以这样做。怎么了?

(对于它的价值,我使用的是 Django 1.3.2)

4

1 回答 1

2

尝试使用数据库后端的完整路径:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        ...
    }
}
于 2012-12-19T15:42:04.867 回答