1.安裝pip install django-crontab
2.settings.py
INSTALLED_APPS
中添加 'django_crontab'
3.設(shè)置function
在 pc.py 中添加方法
def test():
print('django_crontab test')
4.settings.py
每天早上8 點(diǎn)開(kāi)始跑定時(shí)任務(wù)
# CRONJOBS = [
# ('0 8 * * *', 'pc.cron.get_urls','>>/home/cronfile/test.log'),
# ]
5.添加定時(shí)任務(wù)
python manage.py crontab add
備注
1.移除定時(shí)任務(wù)
python manage.py crontab remove
2.查看定時(shí)任務(wù)
crontab -l