【问题标题】:Getting TypeError: 'Module' object is not callable on celery task decorator获取 TypeError:'Module' 对象在 celery 任务装饰器上不可调用
【发布时间】:2012-06-02 17:26:39
【问题描述】:

为 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

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

【问题讨论】:

    标签: django celery


    【解决方案1】:

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

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

    当像这样使用导入时:

    from celery.task import task
    

    似乎一切正常。

    【讨论】:

    • 但是,通过该导入,我收到了弃用警告。更好:from celery.tasks import task.
    猜你喜欢
    • 2020-08-19
    • 1970-01-01
    • 2021-11-22
    • 2019-04-29
    • 2020-09-22
    • 2019-11-18
    • 2021-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多