Django芹菜找不到芹菜模块 [英] Django celery not finding celery module

查看:86
本文介绍了Django芹菜找不到芹菜模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从tut中使用Django设置celery,但我不断得到

  ModuleNotFoundError:没有名为 celery'

我有一个名为Tasklist的主项目,其结构为:

 -任务列表/ 
-manage.py
-任务列表/
-__init__.py
-settings.py
-celery.py
-urls.py

我的初始值 .py如下:

$ ________________________________ __future__ import absolute_import,unicode_literals

。 celery import app as celery_app

__all__ = ['celery_app']

我的celery.py就像这样:

  from __future__ import absolute_import,unicode_literals 
import os
从celery import Celery

app = Celery('')

@ app.task(bind = True)
def debug_task(self):
打印( '请求:{0!r}'。format(self.request))

我不确定是否需要更改settings.py-但是我在本地环境中运行,因此不需要启动芹菜工人?我很困惑!



我读到django-celery是多余的,因为最新版本的celery在这里,所以我只安装了celery 4.1.1。

解决方案

步骤:


  1. 如果celery安装在virtualEnv上,激活VirtualEnv

  2. 导航至路径: / path / to / Tasklist / (至应用程序名称级别)

  3. 运行 celery -A Tasklist worker -l info

-A为应用程序名称。



Celery设置和安装:正式文件



在Settings.py中可以管理以下设置。

  BROKER_URL ='redis:// localhost:6379/0'
CELERY_ACCEPT_CONTENT = ['application / json']
CELERY_TASK_SERIALIZER ='json'
CELERY_RESULT_SERIALIZER ='json'


I'm trying to set up celery with Django from the tuts but I keep getting

ModuleNotFoundError: No module named 'celery'

I have a main project called Tasklist with the structure:

- Tasklist/
  - manage.py
  - Tasklist/
    - __init__.py
    - settings.py
    - celery.py
    - urls.py

My init.py is as follows:

from __future__ import absolute_import, unicode_literals

from .celery import app as celery_app

__all__ = ['celery_app']

And my celery.py is like so:

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? 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.

解决方案

Steps:

  1. If celery installed on virtualEnv , Activate VirtualEnv
  2. Navigate to path : /path/to/Tasklist/ (to app name level)
  3. Run celery -A Tasklist worker -l info

-A for App Name.

Celery Setup and Installation : Official Document

In Settings.py Below setting can be managed.

BROKER_URL = 'redis://localhost:6379/0'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

这篇关于Django芹菜找不到芹菜模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆