(Django-Celery错误)ImportError:没有名为myproject

时间:2018-04-26 05:54:24

标签: python django celery django-celery

我第一次使用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项目结构如下所示:

  • MYPROJECT
    • MYPROJECT
      • 初始化的.py
      • celery.py
      • settings.py
      • urls.py
      • wsgi.py
    • MYAPP
      • 迁移/
      • 模板/
      • 初始化的.py
      • admin.py
      • apps.py
      • forms.py
      • models.py
      • tasks.py
      • tests.py
      • urls.py
      • views.py
    • db.sqlite3
    • manage.py

0 个答案:

没有答案