【发布时间】:2016-11-11 21:05:11
【问题描述】:
Django 版本 1.9.7。
我目前的项目结构是:
vehicles/
├── etl
│ ├── etl
│ ├── manage.py
│ ├── pipeline
│ └── bku
└── web
├── db.sqlite3
├── manage.py
├── profiles
├── projects
├── reverse
├── static
├── templates
├── bku
│ ├── admin.py
│ ├── admin.pyc
│ ├── apps.py
│ ├── migrations
│ ├── models.py
│ ├── static
│ ├── templates
│ ├── tests.py
│ ├── urls.py
│ ├── views.py
│ └── views.pyc
└── rocket
├── celery.py
├── __init__.py
├── settings
│ ├── base.py
│ ├── dev.py
│ ├── __init__.py
│ ├── local.py
│ ├── production.py
│ ├── test.py
├── urls.py
├── wsgi.py
现在我想在bku Django 应用程序中使用Celery。但是当我运行工人celery -A rocket worker -l info 时,我收到以下错误django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.。我已经定义了SECRET_KEY,在尝试 Celery 之前我没有出现此错误。
我怎样才能运行工人?
rocket/celery.py
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rocket.settings')
app = Celery('rocket')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
rocket/init.py
from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app
__all__ = ['bku']
【问题讨论】:
-
@KevinChristopherHenry 你是对的,设置路径是错误的。我通过了
rocket.settings.base,现在 Celery 工作得很好。谢谢你。发表你的答案,我会投票赞成。