【问题标题】:Does django_background_tasks support django 3 and python 3.7?django_background_tasks 是否支持 django 3 和 python 3.7?
【发布时间】:2020-07-20 14:07:30
【问题描述】:

app/tasks.py

from background_task import background

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

app/views.py

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

我已将django_background_tasks 放入 INSTALLED_APPS 并运行迁移。

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

【问题讨论】:

  • @user1242848 问题解决了吗?更新您的状态

标签: python django django-views


【解决方案1】:

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

正如@phi 提到的here

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

运行python manage.py process_tasks 并不孤单来完成这项工作。您需要首先让服务器处于活动状态并运行,然后在另一个 terminal/cmd-line 中运行上述命令。

请参阅文档中的 here

【讨论】:

  • 输入命令后没有任何反应
  • 您的服务器是否已启动并正在运行?你在另一个终端尝试 cmd?
  • 这次成功了。但我提出了问题。是否需要django设置时区?以及schedulerepeat之间的区别
  • 我会这么认为,虽然我不完全确定。稍后我会研究并更新。
猜你喜欢
  • 2018-12-16
  • 2014-08-16
  • 2013-06-27
  • 1970-01-01
  • 1970-01-01
  • 2014-11-07
  • 1970-01-01
  • 1970-01-01
  • 2020-02-07
相关资源
最近更新 更多