7

在为 django 试用 celery 时,我遇到了 @task 装饰器的问题。这是在 Windows 7 上运行的。

在我的 celerytest.tasks 模块中,我有以下代码

from celery import task

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

从命令提示符我运行:

python manage.py shell

尝试从 shell 导入我的模块:

from celerytest.tasks import add

我收到以下错误:

>>> from celerytest.tasks import add
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "d:\...\celerytest\tasks.py", line 8, in <module>
   @task
TypeError: 'module' object is not callable

我试着用谷歌搜索了很长时间,但似乎我是世界上唯一一个遇到这个问题的人。

4

1 回答 1

11

好吧,我正在阅读 2.6.0 rc3 的文档,但安装了 2.5.3。

http://ask.github.com/celery/django/first-steps-with-django.html

像这样使用导入时:

from celery.task import task

一切似乎都有效。

于 2012-06-02T17:53:08.000 回答