Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django Cron,从视图执行def_Python_Django_Cron - Fatal编程技术网

Python Django Cron,从视图执行def

Python Django Cron,从视图执行def,python,django,cron,Python,Django,Cron,我有个问题。 我需要实现一个循环调用的函数 我必须调用dashgenerate函数,因为它会生成数据记录 此cron.py: from django_cron import CronJobBase, Schedule from django.shortcuts import get_object_or_404, render, redirect from django.http import HttpResponse, HttpResponseRedirect, Http404 class M

我有个问题。 我需要实现一个循环调用的函数 我必须调用dashgenerate函数,因为它会生成数据记录

此cron.py:

from django_cron import CronJobBase, Schedule
from django.shortcuts import get_object_or_404, render, redirect
from django.http import HttpResponse, HttpResponseRedirect, Http404

class MyCronJob(CronJobBase):
    RUN_EVERY_MINS = 60
    schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
    code = 'CRM.my_cron_job'
    def do(self):
        return redirect('dashboard/dashgenerate/')
dashgenerate是项目中另一个应用程序的def:

def dashgenerate(request):
.....

为什么需要调用view函数?这个函数“dashgenerate”将记录生成数据库,我希望他每小时都这样做。您可以编写“task”函数,它不希望请求对象作为参数。尽管视图函数更新数据库,但它不必是视图,它可以是普通的python函数,但当通过页面上的相应按钮调用时,该函数也可以工作。为什么不将函数包装成单独的函数,然后从Cron中的“do”函数或视图函数调用该函数?