python - 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_tasks
INSTALLED_APPS 并运行迁移。
但是当我尝试使用命令运行任务时,python manage.py process_tasks
该命令根本不起作用。当我在编写命令后按回车键时,什么也没有发生。
解决方案
首先,确保您使用的是 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
运行上述命令。
从文档中查看此处。
推荐阅读
- python-3.x - 请让我知道为什么我会收到此错误 UnboundLocalError: local variable 'top_performer' referenced before assignment
- django - 在 Django 中测试,没有找到没有参数的反向
- c++ - C++ 循环依赖,未声明的标识符
- c++ - 为什么我们需要在 C++20 中的 map emplace 中使用 piecewise_construct?
- python - 使用用户函数进行 Python 列表排序。(错误)
- java - 无法在 Intellij Idea 的 Springboot 项目中通过模板创建 jsp 文件
- c# - 从控制器显示列表到 Razor 视图 C# MVC 5
- javascript - 从过滤对象数组中删除具有特定键值的对象
- python - plt.scatter 错误 'NoneType' 对象在成功运行后没有属性 'sqrt'
- java - 无法使用 Selenium 找到 Web 元素