Cron Jobs with django-crontab

A snippet showing how to run scheduled tasks with django-crontab.


# settings.py
INSTALLED_APPS = [
    # ...
    'django_crontab',
]

CRONJOBS = [
    ('0 2 * * *', 'myapp.management.commands.cleanup_old_data'),
    ('*/30 * * * *', 'myapp.tasks.send_reminders'),
]

# Install: pip install django-crontab
# Add jobs: python manage.py crontab add
# Remove jobs: python manage.py crontab remove
# Show jobs: python manage.py crontab show
  
Explanation:
  • django-crontab integrates Django management commands with system cron.
  • Define periodic jobs in CRONJOBS setting using cron syntax (minute hour day month weekday).
  • Use python manage.py crontab add to register jobs with system cron.
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.