Django Cron Jobs Django.How

Author avatar wrote on 31/05/2022

1. Install

pip install django-crontab

2. Add django_crontab to INSTALLED_APPS


INSTALLED_APPS = [
    'django_crontab',
    ...
]

3. Create a file myapp/cron.py and create your function

def my_cron_job():
    # your functionality goes here
    Print(time.now())

4. Add the following line to your django project’s settings.py file

CRONJOBS = [
    ('*/2 * * * *', 'myapp.cron.my_cron_job')
]
'*/2 * * * *' runs at every 2nd minute of each hour.

Resources
  • https://gutsytechster.wordpress.com/2019/06/24/how-to-setup-a-cron-job-in-django
  • https://pypi.org/project/django-crontab
  • https://stackoverflow.com/questions/38589830/django-crontab-not-executing-test-function