[英]Django celery not finding celery module
I'm trying to set up celery with Django from the tuts but I keep getting 我正在尝试从tut和Django一起建立芹菜,但我一直
ModuleNotFoundError: No module named 'celery'
I have a main project called Tasklist with the structure: 我有一个名为Tasklist的主项目,其结构如下:
- Tasklist/
- manage.py
- Tasklist/
- __init__.py
- settings.py
- celery.py
- urls.py
My init .py is as follows: 我的init .py如下:
from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app
__all__ = ['celery_app']
And my celery.py is like so: 我的celery.py就像这样:
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
app = Celery('')
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
I'm not sure if I need to alter the settings.py - but I'm running in a local environment so I shouldn't need to start a celery worker? 我不确定是否需要更改settings.py-但是我在本地环境中运行,所以我不需要启动芹菜工人吗? I'm pretty confused!
我很困惑!
I read that django-celery is redundant now the latest version of celery is here, so I only have celery 4.1.1 installed. 我读到django-celery是多余的,现在最新版本的celery在这里,所以我只安装了celery 4.1.1。
Steps: 脚步:
/path/to/Tasklist/
(to app name level) /path/to/Tasklist/
(到应用程序名称级别) celery -A Tasklist worker -l info
celery -A Tasklist worker -l info
-A for App Name. -A为应用程序名称。
Celery Setup and Installation : Official Document Celery设置和安装: 官方文档
In Settings.py Below setting can be managed. 在Settings.py以下可以管理设置。
BROKER_URL = 'redis://localhost:6379/0'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.