美文网首页
2018-07-26

2018-07-26

作者: 唱故事的人呀 | 来源:发表于2018-07-26 18:11 被阅读0次

1 安装包

pip install apscheduler==2.1.2

2 安装完成后,在django项目urls.py中增加以下内容

from apscheduler.scheduler import Scheduler

from myapp.views import hello

sched = Scheduler()

@sched.interval_schedule(seconds=60) # 表示间隔一分钟会执行函数

def mytask():

       hello()

sched.start()

myapp/ views.py 文件

def hello():     

      print('hello')

3 启动django项目, 每隔一分钟会执行一次hello函数

 python manage.py runserver 

# 执行效果如下所示:

System check identified 1 issue (0 silenced).

Run 'python manage.py migrate' to apply them.

July 26, 2018 - 18:09:00

Django version 2.0.6, using settings 'myapp.settings'

Starting development server at http://127.0.0.1:8000/

Quit the server with CONTROL-C.

hello

hello

hello

相关文章

网友评论

      本文标题:2018-07-26

      本文链接:https://www.haomeiwen.com/subject/mhtimftx.html