标签:receiver sch 队列 djang lis rem email task def
django-crontab
这个第三包来实现django-crontab
只能在linux系统下使用pip install django-crontab
from django.core.mail import send_mail
from django.conf import settings
from django.template.loader import render_to_string
from task.models import Task
from django.contrib.auth.models import User
def send_task_email():
user_list = User.objects.filter()
for user in user_list:
tasks = Task.objects.filter(status=False, user=user)
if tasks:
html_message = render_to_string('task/task.html', {'tasks': tasks, 'user': user})
subject = '任务提醒'
message = ''
sender = settings.EMAIL_FROM
receiver = [user.email]
send_mail(subject, message, sender, receiver, html_message=html_message)
CRONJOBS = [
('00 10 * * *', 'task.scheduled_task.send_task_email', '>>task.log'),
]
00 10 * * *
是每天10点执行python # crontab范例 # 每五分钟执行 */5 * * * * # 每小时执行 0 * * * * # 每天执行 0 0 * * * # 每周执行 0 0 * * 0 # 每月执行 0 0 1 * *
python manage.py crontab add
python manage.py crontab show
python manage.py crontab remove
标签:receiver sch 队列 djang lis rem email task def
原文地址:https://www.cnblogs.com/ivy-blogs/p/11695551.html