django-celery 的示例在 Django 应用程序中不起作用
我正在关注本教程
http://celeryq。 org/docs/django-celery/getting-started/first-steps-with-django.html
启动了芹菜
我用python manage.py celeryd
然后我做了myapp
文件夹中的 tasks.py
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 shell
然后我使用python manage.py shell
然后我 键入
从 myapp import jobs 中
一切顺利,
但是当我键入函数名称时,我收到错误
add.delay(4, 4)
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'add' is not defined
我缺少什么
I am following this tutorial
http://celeryq.org/docs/django-celery/getting-started/first-steps-with-django.html
I startd the celery with
python manage.py celeryd
Then i made tasks.py
in myapp
folder with
from celery.decorators import task
@task()
def add(x, y):
return x + y
Then i put these in 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 = "/"
Then i started the python shell with
python manage.py shell
Then i type
from myapp import tasks
It went ok
But when i type function name then i get error
add.delay(4, 4)
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'add' is not defined
What i am missing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你在shell里面做了这个吗?
如果是这样,您需要这样调用它:
或者您需要将导入更改为以下内容:
Inside of the shell did you do this?
If so, you need to call it like this:
Or you will need to change the import to the following: