首页 > 解决方案 > django_background_tasks 是否支持 django 3 和 python 3.7?

问题描述

应用程序/tasks.py

from background_task import background

@background(schedule=60)
def schedule_task():
    print('running_tasks')

应用程序/views.py

schedule_task(repeat=300, repeat_until=obj.end_date)

我已放入django_background_tasksINSTALLED_APPS 并运行迁移。

但是当我尝试使用命令运行任务时,python manage.py process_tasks该命令根本不起作用。当我在编写命令后按回车键时,什么也没有发生。

标签: pythondjangodjango-views

解决方案


首先,确保您使用的是 django-background-task不是 django-background-task。

正如@phi在这里提到的

django-background-task 和 django-background-task之间有区别django-background-task 未维护并且与较新的 Django 版本不兼容。不久前,我们使用新功能对其进行了更新和扩展,并在Github上维护了新向后兼容包 django-background-task 。可以从PyPI下载或安装新的 django-background-tasks 应用程序。

跑步python manage.py process_tasks并不是唯一能让这项工作发挥作用的人。您需要首先让服务器处于活动状态并运行,然后在另一个terminal/cmd-line运行上述命令。

从文档中查看此处。


推荐阅读