我之前使用的是celery 4.1.1版本,升级到4.2.1之后,celery开始引起
django.core.exceptions.ImproperlyConfigured:无法导入
这是我的 celery.py
import os
import sys
from celery import Celery
from django.apps import apps, AppConfig
from django.conf import settings
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.dev') # pragma: no cover
app = Celery('app')
app.config_from_object('django.conf:settings', namespace='CELERY')
class CeleryConfig(AppConfig):
name = 'app.taskapp'
verbose_name = 'Celery Config'
def ready(self):
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
if hasattr(settings, 'RAVEN_CONFIG'):
# some code
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request)) # pragma: no cover
4.1.1完美运行。有什么建议吗?