Django celery not finding celery module

别来无恙 提交于 2019-12-11 13:25:03

问题


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.


回答1:


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'


来源:https://stackoverflow.com/questions/50785095/django-celery-not-finding-celery-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!