我正在关注this在 Heroku 上运行 celery 和 django 的教程。
但是,当我为工作人员输入指定的代码时,我在日志中收到此错误:
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']
之前进行同步时,它运行良好。根据the document
When you deploy a Django application, the compile process appends the following code to your settings.py to use the DATABASE_URL environment variable:
最佳答案
Heroku 在 settings.py
末尾添加 DATABASES
配置,因此当您在 settings.py 中引用 DATABASES
时,它不存在。
您可以在自己的文件中复制 Heroku DATABASES
设置(它只是从 env 的 DATABASE_URL
读取,请参阅: django-heroku-template )或使用您自己的 buildpack .
关于django - Heroku Django celery : NameError: name 'DATABASES' is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8599857/