1

我正在关注本教程

http://celeryq.org/docs/django-celery/getting-started/first-steps-with-django.html

我开始用芹菜

python manage.py celeryd

然后我tasks.pymyapp文件夹中制作

from celery.decorators import task

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

然后我把这些放在 settings.py

import djcelery
djcelery.setup_loader()

    CELERY_RESULT_BACKEND = "database"
    CELERY_RESULT_DBURI = "mysql://user1:password@localhost/ajfdfa_rabbitmq"

    BROKER_HOST = "localhost"
    BROKER_PORT = 5672
    BROKER_USER = "guest"
    BROKER_PASSWORD = "guest"
    BROKER_VHOST = "/"

然后我用

python manage.py shell

然后我输入

从 myapp 导入任务

一切顺利

但是当我输入函数名称时,我得到了错误

add.delay(4, 4)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'add' is not defined

我错过了什么

4

1 回答 1

3

在外壳里面你是这样做的吗?

from myapp import tasks

如果是这样,您需要这样称呼它:

tasks.add(4,4)

或者您需要将导入更改为以下内容:

from myapp.tasks import add
add(4,4)
于 2011-07-11T15:28:17.283 回答