use*_*418 5 django heroku celery
我正在尝试按照此处的说明在 Heroku 上启动 celery 并运行
当我尝试运行“heroku local”时,但出现以下错误:
10:05:42 PM worker.1 | Error:
10:05:42 PM worker.1 | Unable to load celery application.
10:05:42 PM worker.1 | The module tasks was not found.
Run Code Online (Sandbox Code Playgroud)
任何帮助深表感谢。
编辑:应该注意的是,我的根目录中有一个模块tasks.py,其中包含以下代码:
import celery
app = celery.Celery('example')
@app.task
def add(x, y):
return x + y
Run Code Online (Sandbox Code Playgroud)
小智 3
根据评论,我认为您需要在项目文件夹(与 celery.py 相同的文件夹)中填充init .py 。您可以按照Celery 官方文档进行操作。
这是您应该添加到__init__.py 的内容:
from __future__ import absolute_import, unicode_literals
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
__all__ = ('celery_app',)
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。