问题
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:
- If celery installed on virtualEnv , Activate VirtualEnv
- Navigate to path :
/path/to/Tasklist/
(to app name level) - 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