Python 如何在运行芹菜任务时修复此错误

Python 如何在运行芹菜任务时修复此错误,python,django,celery,django-celery,celery-task,Python,Django,Celery,Django Celery,Celery Task,当我尝试运行此代码时,它会抛出一个错误, 我想将task_number_one和print_test作为周期性任务运行,但这两个任务都会抛出相同的错误 from celery.task import periodic_task from celery.schedules import crontab from celery import task @task() def task_number_one(): print("Celery Task Working...") @period

当我尝试运行此代码时,它会抛出一个错误, 我想将task_number_one和print_test作为周期性任务运行,但这两个任务都会抛出相同的错误

from celery.task import periodic_task
from celery.schedules import crontab
from celery import task
@task()
def task_number_one():
    print("Celery Task Working...")

@periodic_task(run_every=crontab(minute='10', hour='6,8,9,10,11,12'))
def print_test():
   print(1)

task_number_one.delay()
我得到下面的错误

[2019-09-18 17:21:17,093: ERROR/MainProcess] Received unregistered task of type 'page.tasks.task_number_one'.
The message has been ignored and discarded.

Did you remember to import the module containing this task?
Or maybe you're using relative imports?

Please see
http://docs.celeryq.org/en/latest/internals/protocol.html
for more information.

The full contents of the message body was:
'[[], {}, {"callbacks": null, "errbacks": null, "chain": null, "chord": null}]' (77b)
Traceback (most recent call last):
  File "/home/naanal/venv/lib/python3.6/site-packages/celery/worker/consumer/consumer.py", line 559, in on_task_received
    strategy = strategies[type_]
KeyError: 'page.tasks.task_number_one'

如果您使用的是芹菜v4,那么注册任务的方式与使用v3时不同。对于v4,请使用以下命令:

from myapp.celery import app

@app.task
def task_number_one():
    print("Celery Task Working...")

您必须将此任务导入到存储有
芹菜()
对象的文件中,我相信..可能是