开发者

Why do I have to put the project name when importing tasks when using Django with Celery?

I just installed and configured Celery with RabbitMQ for a Django project and I was having an issue running tasks when I imported them like so:

from someapp.tasks import SomeTask
开发者_运维百科

It worked when I added the project name:

from myproject.someapp.tasks import SomeTask

I tried adding this into the settings.py file but it doesn't change anything:

CELERY_IMPORTS = ("myproject.someapp.tasks",)

I'm fine with leaving the project name on the import line since it works but I'd like to know if there's a way around it or why it has to be that way.


It's probably because you have

INSTALLED_APPS = ("myproject.someapp", )

Instead you should add the directory containing the apps on the Python path (the project in this case), and simply do

INSTALLED_APPS = ("someapp", )

IMHO this makes more sense for an "app" anyway.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜