我正在采取第一步在我的Django应用程序中添加芹菜任务。但是我仍然收到错误。
File "C:UserstymotDesktopsend_sms_oferiaapp_ramaapp_rama__init__.py", line 5, in <module>
from .celery import app as celery_app
File "C:UserstymotDesktopsend_sms_oferiaapp_ramaapp_ramacelery.py", line 17, in <module>
app.autodiscover_tasks()
TypeError: autodiscover_tasks() missing 1 required positional argument: 'packages'
此错误来自哪里?我该如何解决?
我尝试按照本文档执行我的步骤,因此我的文件看起来像这样:Celery.py(在我的项目目录中(:
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app_rama.settings')
app = Celery('app_rama')
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings')
# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
我的__init__.py
文件(在我的项目目录中(
from __future__ import absolute_import, unicode_literals
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
__all__ = ('celery_app',)
尝试将安装的应用程序传递给autodiscover_tasks
,例如:
from django.conf import settings
app.autodiscover_tasks(settings.INSTALLED_APPS)
检查此功能的文档