【发布时间】:2017-09-29 18:01:52
【问题描述】:
我正在尝试学习如何使用 schedule 包在 Django 中安排任务。这是我添加到视图中的代码。我应该提到我只有一个视图,所以我需要在我的索引视图中运行调度程序。我知道代码逻辑存在问题,它只会渲染调度程序并且会陷入循环。你能告诉我我该怎么做用吗?
def job():
print "this is scheduled job", str(datetime.now())
def index(request):
schedule.every(10).second.do(job())
while True:
schedule.run_pending()
time.sleep(1)
objs= objsdb.objects.all()
template = loader.get_template('objtest/index.html')
context= { 'objs': objs}
return HttpResponse(template.render(context, request))
【问题讨论】: