【发布时间】:2014-03-12 07:00:30
【问题描述】:
在 Heroku 上使用 Django,dynos 几乎立即崩溃。在日志错误中,它提到未定义“DATABASES”。这是日志:
2014-02-13T11:32:38.373434+00:00 app[web.1]: 2014-02-13 11:32:38 [7] [INFO] Worker exiting (pid: 7)
2014-02-13T11:32:38.373434+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
2014-02-13T11:32:38.373434+00:00 app[web.1]: __import__(name)
2014-02-13T11:32:38.373434+00:00 app[web.1]: NameError: name 'DATABASES' is not defined
2014-02-13T11:32:38.373434+00:00 app[web.1]: DATABASES['default'] = dj_database_url.config()
2014-02-13T11:32:38.569277+00:00 heroku[web.1]: State changed from starting to crashed
2014-02-13T11:32:38.569974+00:00 heroku[web.1]: State changed from crashed to starting
2014-02-13T11:32:38.505867+00:00 app[web.1]: 2014-02-13 11:32:38 [2] [INFO] Shutting down: Master
2014-02-13T11:32:38.505867+00:00 app[web.1]: 2014-02-13 11:32:38 [2] [INFO] Reason: Worker failed to boot.
2014-02-13T11:32:38.557996+00:00 heroku[web.1]: Process exited with status 3
2014-02-13T11:32:39.808509+00:00 heroku[web.1]: Process exited with status 3
2014-02-13T11:32:42.728831+00:00 heroku[web.1]: Starting process with command `gunicorn counter.wsgi`
2014-02-13T11:32:43.803689+00:00 app[web.1]: 2014-02-13 11:32:43 [2] [INFO] Starting gunicorn 18.0
2014-02-13T11:32:43.807267+00:00 app[web.1]: 2014-02-13 11:32:43 [2] [INFO] Listening at: http://0.0.0.0:44456 (2)
2014-02-13T11:32:43.807741+00:00 app[web.1]: 2014-02-13 11:32:43 [2] [INFO] Using worker: sync
2014-02-13T11:32:43.819443+00:00 app[web.1]: 2014-02-13 11:32:43 [7] [INFO] Booting worker with pid: 7
2014-02-13T11:32:43.939156+00:00 app[web.1]: 2014-02-13 11:32:43 [7] [ERROR] Exception in worker process:
2014-02-13T11:32:43.939156+00:00 app[web.1]: Traceback (most recent call last):
2014-02-13T11:32:43.939156+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
2014-02-13T11:32:43.939156+00:00 app[web.1]: worker.init_process()
2014-02-13T11:32:43.939156+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
...
...
...
然后继续。
我相信这可能与我按照 Heroku 设置指南的指示更改我的 settings.py 时有关。下面附上文件:
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
SECRET_KEY = 'c_ctc!-&!zyug%xh3&xi_v#1cs0xkr8!t_+y+f0ecc1)7dypz('
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = ['*']
<span style="font-family:"Helvetica Neue","Helvetica","Arial",sans-serif;font-size:13px"></span>
<span style="font-family:"Helvetica Neue","Helvetica","Arial",sans-serif;font-size:13px">INSTALLED_APPS = (</span>
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'users',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'counter.urls'
WSGI_APPLICATION = 'counter.wsgi.application'
import dj_database_url
DATABASES['default'] = dj_database_url.config()
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
我想知道这是否与 dj_database_url.config() 没有正确调用有关,因为 dj_database_url 没有正确导入? settings.py 已按照此处的说明进行编辑:https://devcenter.heroku.com/articles/getting-started-with-django#django-settings
另外,当我运行 $>heroku run python manage.py runservers 时,我得到以下信息:
Running `python manage.py runservers` attached to terminal... up, run.2614
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
commands = get_commands()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 128, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/app/counter/settings.py", line 59, in <module>
DATABASES['default'] = dj_database_url.config()
NameError: name 'DATABASES' is not defined
【问题讨论】:
标签: python sql database django heroku