【发布时间】:2017-09-25 18:11:49
【问题描述】:
ModuleNotFoundError: No module named 'myapp'
我真的不明白这里的问题是什么。我的应用程序没有问题,但无论我尝试和更改什么,celery 似乎都找不到它。
这是我的目录结构:
django
/ mysite
__init__.py
celery.py
settings.py
urls.py
wsgi.py
/ myapp
admin.py
apps.py
models.py
tasks.py
urls.py
views.py
manage.py
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', 'mysite.settings')
app = Celery('myapp')
# Using a string here means the worker don'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', namespace='CELERY')
# 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))
命令:celery -A myapp worker -l info
【问题讨论】:
-
第一个命令结果:
AttributeError: module 'celery' has no attribute 'celery'第二个命令结果:ModuleNotFoundError: No module named 'myapp' -
我已经对我的答案添加了一个编辑。
标签: django django-models django-templates django-celery