Sorry for my english. I new in django, i want send email every 1 min. I found this solution i follow it. But my django_cron run only one.
i installed django_cron like this: pip install django_cron
then i added app to INSTALLED_APPS
INSTALLED_APPS = [
..
'django_cron',
'accounts',
...
]
and add to settings:
CRON_CLASSES = [
"accounts.cron.MyCronJob",
]
then run python manage.py migrate django_cron
in app accounts
i create file cron
and add this code:
from django.core.mail import EmailMessage
from django.template.loader import render_to_string
from django_cron import CronJobBase, Schedule
class MyCronJob(CronJobBase):
RUN_EVERY_MINS = 1
schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
code = 'accounts.cron.MyCronJob' # a unique code
def do(self):
print("send message")
message = render_to_string('cron_file.html', {
'name': '111'
})
mail_subject = 'Congratulations'
to_email = 'test@gmail.com'
email = EmailMessage(mail_subject, message, to=[to_email])
email.send()
then run python manage.py runcrons
but message send only once when i call command python manage.py runcrons