Django+Apscheduler 开发定时任务模块
目录
本文章要实现的是Django+Apscheduler 开发定时任务模块,并使用uwsgi+nginx模式部署,
且能避免多进程下任务重复执行,且能够页面动态操作任务;
准备环境
python3.6 django3.6 redis nginx uwsgi simpleui(一个前端组件)
版本非必需指定,但也没有全部测试,只是本人所用
搭建项目
构建django项目
略,不会的话自行百度吧
使用simpleui
1、安装simpleui
pip install django-simpleui
2、添加simpleui到项目,注意下方代码第二行,不要忘记结尾逗号
INSTALLED_APPS = [
'simpleui',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
3、收集静态文件
在项目根目录执行
python manage.py collectstatic
4、修改urls.py,直接展示修改后的内容吧
from django.contrib import admin
from django.conf.urls import url, include
from django.views import static
from automan import settings
urlpatterns = [
url(r'^admin/(?P<path>.*)$', static.serve, {'document_root': settings.STATIC_ROOT}, name='static'),
url(r'^', admin.site.urls),
]
忘记STATIC_ROOT是我加的还是创建项目就带的了,如果settings.py内没有的话,就加一下:
STATIC_ROOT = 'static'
5、创建超级用户
在项目根目录执行
python manage.py createsuperuser
然后根据提示继续输入就好了
ok,到这里项目就已经搭建好了,自己测试一下能否正常运行,看下截图,下篇文章开始添加定时任务的model
附上simpleui操作文档链接
2022-04-10