{"id":8092,"library":"django-crontab","title":"Django Crontab","description":"django-crontab is a Python library providing dead-simple job scheduling for Django applications, leveraging the system's `crontab` utility. The latest version is 0.7.1, released in March 2016. Due to its age and lack of recent updates, it is best suited for legacy Django projects (up to Django 2.0) or users prepared to address potential issues themselves.","status":"abandoned","version":"0.7.1","language":"en","source_language":"en","source_url":"https://github.com/kraiz/django-crontab","tags":["django","cron","scheduling","jobs","automation","legacy"],"install":[{"cmd":"pip install django-crontab","lang":"bash","label":"Install latest stable version"}],"dependencies":[{"reason":"The library explicitly states compatibility with Django 1.8-2.0. Newer Django versions may have compatibility issues due to the lack of updates.","package":"Django"}],"imports":[{"note":"Configuration is primarily done via the CRONJOBS setting in settings.py, pointing to a Python callable, rather than direct module imports for scheduling logic.","symbol":"CRONJOBS (setting)","correct":"CRONJOBS = [('*/5 * * * *', 'myapp.cron.my_scheduled_job')]"}],"quickstart":{"code":"import os\n\n# settings.py\nINSTALLED_APPS = [\n    # ...\n    'django_crontab',\n    'myapp', # Your app containing the cron job\n]\n\nCRONJOBS = [\n    # Run 'myapp.cron.my_scheduled_job' every 5 minutes\n    ('*/5 * * * *', 'myapp.cron.my_scheduled_job'),\n    # Example calling a Django management command daily at midnight\n    ('0 0 * * *', 'django.core.management.call_command', ['clearsessions']),\n    # Example with arguments and redirecting output to a log file\n    ('0 0 * * 0', 'django.core.management.call_command', ['dumpdata', 'auth'], {'indent': 4}, f'> {os.environ.get('DJANGO_CRON_LOG_DIR', '/tmp')}/last_sunday_auth_backup.json'),\n]\n\n# myapp/cron.py\n# Create this file in your Django app\n\ndef my_scheduled_job():\n    # Your periodic task logic goes here\n    print('My scheduled job ran!')\n    # Example: Log to a file or database\n    with open(f'{os.environ.get('DJANGO_CRON_LOG_DIR', '/tmp')}/django_crontab_log.txt', 'a') as f:\n        f.write('Job executed at ' + str(os.time.time()) + '\\n')\n\n# After configuring, run in your terminal:\n# python manage.py crontab add\n# To view jobs:\n# python manage.py crontab show\n# To remove jobs:\n# python manage.py crontab remove","lang":"python","description":"To quickly set up `django-crontab`, first add `django_crontab` to your `INSTALLED_APPS`. Then, define your scheduled functions within a Python file (e.g., `myapp/cron.py`). Finally, specify these jobs in your `settings.py` using the `CRONJOBS` list, and activate them by running `python manage.py crontab add`. Remember to run `crontab add` after any changes to `CRONJOBS`."},"warnings":[{"fix":"Consider alternative scheduling libraries like `django-apscheduler` or `django-cron` for modern Django projects, or be prepared to fork and maintain `django-crontab` yourself.","message":"The project is effectively abandoned, with the last release in March 2016. This means critical bugs, security vulnerabilities, or incompatibilities with newer Python/Django versions (beyond Django 2.0) are unlikely to be addressed.","severity":"breaking","affected_versions":"0.7.1 and older"},{"fix":"Always execute `python manage.py crontab add` after any change to your `CRONJOBS` list. To remove all jobs, use `python manage.py crontab remove`.","message":"You MUST run `python manage.py crontab add` every time you modify the `CRONJOBS` setting in your `settings.py`. Forgetting this step is a very common reason why scheduled tasks do not run as expected.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Deploy your Django application to a Linux-based environment (e.g., Docker container, VPS) for `django-crontab` to function correctly. Consider Windows-compatible task schedulers or alternative Django-based solutions for Windows development.","message":"The library does not work on Windows operating systems, as it relies on the underlying Unix `crontab` utility.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure the `cron` service is started within your Docker container's entrypoint or `CMD` (e.g., `service cron start && tail -f /var/log/cron.log`). Verify that the Python executable used by cron (often `/usr/local/bin/python` in containers) matches your environment.","message":"When running in Docker or other containerized environments, the cron daemon might not be running by default, or the Python executable path might be incorrect. This can lead to jobs being 'added' but never executing.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"1. Ensure you've run `python manage.py crontab add`. 2. Verify the `cron` service is active on your system (`sudo service cron status` or check Docker logs). 3. Check logs for the cron job's output (if configured) for specific errors. 4. Run `python manage.py crontab show` to confirm jobs are listed.","cause":"This is often caused by the underlying cron daemon not running on the system/container, incorrect paths, or not having run `python manage.py crontab add` after configuration.","error":"No jobs running / Job not executing automatically"},{"fix":"Ensure `django_crontab` is included in your `INSTALLED_APPS` list and that `pip install django-crontab` was executed successfully in the environment where `manage.py` is run.","cause":"The `django_crontab` app has not been added to your `INSTALLED_APPS` in `settings.py`, or the package is not installed in the environment.","error":"Unknown command: 'crontab' or 'manage.py crontab' command not found"},{"fix":"Do not manually edit `crontab -e` entries generated by `django-crontab`. All job modifications (add, change, remove) should be done by adjusting the `CRONJOBS` setting and then running the appropriate `python manage.py crontab` command.","cause":"This is intended behavior of `django-crontab`. It uses hashes to uniquely identify and manage jobs defined in `settings.CRONJOBS`, preventing conflicts and ensuring consistency.","error":"Jobs appear 'encrypted' or hashed in `crontab -e` output, making manual editing difficult."}]}