python - flask 错误 : Unable to load celery application

标签 python python-3.x flask celery celery-task

请帮我解决这个问题 我在运行时遇到了这个问题

celery -A app.celery worker --loglevel=info

错误:
Unable to load celery application.
The module app.celery was not found.

我的代码是——
#  Celery Configuration
from celery import Celery
from app import app
print("App Name=",app.import_name)

celery=Celery(app.name,broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)

@celery.task
def download_content():
    return "hello"

目录结构--
newYoutube/app/auth/routes.py 并且此功能存在于 routes.py 中
auth 是蓝图。

最佳答案

通过调用 celery 时

celery -A app.celery ...

celery 将在 celery 命名空间中查找名称 app ,期望它包含 Celery 的实例。如果你把它放在别处(比如,在 app.auth.routes 中),那么 celery 将找不到它。

我有一个工作示例,您可以从 https://github.com/davewsmith/flask-celery-starter 中获取

或者,引用 Flask Mega Tutorial 的第 22 章,它使用 rx 而不是 celery ,但构建代码的一般方法是相似的。

关于python - flask 错误 : Unable to load celery application,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59472600/

相关文章:

python - pandas matplotlib plot 有奇怪的工件

python - settingWithCopyWarning pandas 通过索引设置

Python 计算 x 接近 0 时的 log(1+x)/x

python - 如何实现 "if-else"条件,其中涉及在多列上乘以数字

python - 属性错误 : 'MyMainWindow' object has no attribute 'pushButton'

python - 模块化固定装置时,PyTest 在具有多个测试文件的目录上失败

python-3.x - 如何将我的 Kivy 客户端连接到服务器(TCP、套接字)

在列表中解压迭代器的 Pythonic 方法

python - gunicorn 在 heroku 中导致错误

python - 通过 ajax 调用 Flask 更改来自另一个驱动器的图像源