5

我正在按照教程让 celery 和 django 在 heroku 上运行。

但是,当我为工作人员输入指定的代码时,我在日志中收到此错误:

2011-12-22T05:31:56+00:00 heroku[web.1]: Starting process with command `python canada/manage.py run_gunicorn -b "0.0.0.0:47336" -w 3`
2011-12-22T05:31:56+00:00 app[web.1]: Unexpected error: (<type 'exceptions.NameError'>, NameError("name 'DATABASES' is not defined",), <traceback object at 0x11a9560>)
2011-12-22T05:31:56+00:00 app[web.1]: Traceback (most recent call last):
2011-12-22T05:31:56+00:00 app[web.1]:   File "canada/manage.py", line 11, in <module>
2011-12-22T05:31:56+00:00 app[web.1]:     import settings
2011-12-22T05:31:56+00:00 app[web.1]:   File "/app/canada/settings.py", line 51, in <module>
2011-12-22T05:31:56+00:00 app[web.1]:     CELERY_RESULT_DBURI = DATABASES['default']
2011-12-22T05:31:56+00:00 app[web.1]: NameError: name 'DATABASES' is not defined
2011-12-22T05:31:57+00:00 heroku[slugc]: Slug compilation finished
2011-12-22T05:31:57+00:00 heroku[web.1]: State changed from starting to crashed
2011-12-22T05:31:58+00:00 heroku[web.1]: Process exited

我的 settings.py 看起来像

import djcelery

djcelery.setup_loader()

BROKER_BACKEND = "djkombu.transport.DatabaseTransport"
CELERY_RESULT_DBURI = DATABASES['default']
...

当我在添加此行之前同步时CELERY_RESULT_DBURI = DATABASES['default'],它运行良好。根据文件

当您部署 Django 应用程序时,编译过程会将以下代码附加到您的 settings.py 以使用 DATABASE_URL 环境变量:

4

2 回答 2

8

Heroku is adding DATABASES configuration at the end of your settings.py, so when you make reference to DATABASESin your settings.py, it doesn't exists.

You can replicate Heroku DATABASES settings in your own file (it just read from DATABASE_URL from env, see : django-heroku-template) or use your own buildpack.

于 2012-01-15T16:49:16.130 回答
0

在运行您的应用程序之前尝试此操作:

export DATABASE_URL='postgres://postuser:postpassword@posthost/dbname'

使用环境变量是 Heroku 自动设置数据库凭据的最简单方法,无需修改 settings.py

于 2011-12-22T07:09:34.310 回答