我第一次使用Django-Celery。当我尝试运行以下命令时:
celery -A MyProject worker -l info
我收到此错误消息:
ImportError: No module named MyProject
MyProject / MyProject / init .py:
from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app
__all__ = ['celery_app']
MyProject的/ MyProject的/ celery.py:
from __future__ import absolute_import
import os
import sys
from celery import Celery
from django.conf import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'MyProject.settings')
app = Celery('MyProject')
app.config_from_object('django.conf:settings', namespace='CELERY')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'MyProject.settings')
sys.path.insert(0,os.path.abspath(os.path.join(os.path.dirname(__file__),'../MyProject')))
app.autodiscover_tasks()
MyProject的/ MyProject的/ settings.py;我在下面写了一行:
CELERY_BROKER_URL = 'amqp://localhost'
我的Django项目结构如下所示: