首先,需要在项目中安装django-crontab库,在项目的settings.py文件中配置INSTALLED_APPS并添加'django_crontab'
然后,在项目的根目录下新建一个cron.py文件,在文件中编写定时任务代码
接着,在项目根目录下执行python manage.py crontab add 命令,将cron.py文件中的定时任务添加到crontab中
最后,在项目根目录下执行python manage.py crontab show 命令,查看已添加的定时任务
例:
1.在项目的settings.py文件中配置INSTALLED_APPS并添加'djang