简体   繁体   中英

Module 'project_name' has no attribute 'celery'

I'm trying to set up a background task using celery and rabbitmq on django but I'm getting an error saying that my project has no attribute celery. I'm using PyCharm and installed celery through that.

I'm new to celery but I've read a lot of articles similar to this issue ( AttributeError: module 'module' has no attribute 'celery' this one seems the closest but not sure it's quite the same)

Project structure:

project_name
├──project_name
|  ├── settings.py
├──app_name1
|  └──celery.py
├──app_name2
|  └──tasks.py

I run the following command:

celery -A project_name worker -l info --pool=solo

But I get the following error:

Error: Invalid value for "-A" / "--app":
Unable to load celery application.
Module 'project_name' has no attribute 'celery'

celery.py file:

from __future__ import absolute_import, unicode_literals

import os

from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project_name.settings')

app = Celery('project_name')

app.config_from_object('django.config:settings', namespace='CELERY')

app.autodiscover_tasks()

tasks.py file:

from __future__ import absolute_import, unicode_literals

from celery import shared_task

@shared_task
def add(x, y):
    return x + y

只是为了记录:将celery.py文件放入主项目文件中,而不是应用程序中。

Try to enter into the project via the terminal. Write:

cd project_name

It worked with me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM