Sample example from django-celery not working in Django app
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 = 开发者_如何学Python"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
Inside of the shell did you do this?
from myapp import tasks
If so, you need to call it like this:
tasks.add(4,4)
Or you will need to change the import to the following:
from myapp.tasks import add
add(4,4)
精彩评论