当前位置: 首页 > news >正文

做一个网站需要多少钱 怎么做网络舆情处置的五个步骤

做一个网站需要多少钱 怎么做,网络舆情处置的五个步骤,wordpress登录密码错误也不报错,时时彩网站建设教程定时任务可以在后台定时执行指定的代码,避免了很多人为操作。下面是在Django项目中如何使用定时任务的具体操作流程。 我在这里使用的 django-apscheduler库来实现定时任务。 一、安装 django-apscheduler pip install django-apscheduler二、在项目的setting.py…

定时任务可以在后台定时执行指定的代码,避免了很多人为操作。下面是在Django项目中如何使用定时任务的具体操作流程。

我在这里使用的 django-apscheduler库来实现定时任务。

一、安装 django-apscheduler

pip install django-apscheduler

二、在项目的setting.py文件中修改配置

在INSTALLED_APPS 中添加 django_apscheduler 项。

三、通过命令生成定时任务记录表

在项目根目录,分别执行以下命令

1、根据数据库模型生成迁移文件

python manage.py makemigrations

2、执行迁移文件

python manage.py migrate

执行完以上两个命令后,在默认的数据库中会生成两个表,django_apscheduler_djangojobexecution 和 django_apscheduler_djangojob.

四、我一般是在项目中新建一个py文件,将所有需要定时执行的任务都保存在这个文件中。

比如我在项目的until目录中新建一个time.py文件。

打开这个文件将以下代码复制到文件中。

from django.shortcuts import render# Create your views here.
from apscheduler.schedulers.background import BackgroundScheduler
from django_apscheduler.jobstores import DjangoJobStore, register_job
from until import logg
from app1 import tests# 实例化调度器
scheduler = BackgroundScheduler()
# 调度器使用默认的DjangoJobStore()
scheduler.add_jobstore(DjangoJobStore(), 'default')# 30秒循环执行
@register_job(scheduler, 'interval', id='test', seconds=30,args=['test'], replace_existing=True)
def test(s):tests.adddata()logg.info("30秒到了,开始执行")# 每天八点半定时执行
@register_job(scheduler, 'cron', id='test1',hour=8, minute=30, args=['test'], replace_existing=True)
def test1(s):logg.info("开始执行")# 单次定时执行
@register_job(scheduler, 'date', id='test2', run_date='2024-06-10 06:06:06',args=['test'], replace_existing=True)
def test2(s):logg.info("30秒到了,开始执行")# 注册定时任务并开始
scheduler.start()

根据注释修改对应的定时任务和所要执行的方法就行。

主要的配置是触发器中的时间配置。可以参考以下参数。

  • date:任务只会执行一次。特定的时间点触发。
run_date (datetime 或 str) 作业的运行日期或时间
timezone (datetime.tzinfo 或 str) 指定时区
  • interval:固定时间间隔触发。
weeks (int) 间隔几周
days (int) 间隔几天
hours (int) 间隔几小时
minutes (int) 间隔几分钟
seconds (int) 间隔多少秒
start_date (datetime 或 str) 开始日期
end_date (datetime 或 str) 结束日期
timezone (datetime.tzinfo 或str) 时区
  • cron:在特定时间周期性地触发,和Linux crontab格式兼容。
year (int 或 str) 年,4位数字
month (int 或 str) 月 (范围1-12)
day (int 或 str) 日 (范围1-31
week (int 或 str) 周 (范围1-53)
day_of_week (int 或 str) 周内第几天或者星期几 (范围0-6 或者 mon,tue,wed,thu,fri,sat,sun)
hour (int 或 str) 时 (范围0-23)
minute (int 或 str) 分 (范围0-59)
second (int 或 str) 秒 (范围0-59)
start_date (datetime 或 str) 最早开始日期(包含)
end_date (datetime 或 str) 最晚结束时间(包含)
timezone (datetime.tzinfo 或str) 指定时区

五、配置好定时任务以后,需要在setting.py同目录的urls文件中引入刚才的文件

from until import ttime

六、然后就可以启动项目了,到时间就可以看到定时任务执行了。


文章转载自:
http://dinncoherniotomy.tqpr.cn
http://dinncomarkswoman.tqpr.cn
http://dinncoforbearance.tqpr.cn
http://dinncopriggery.tqpr.cn
http://dinnconj.tqpr.cn
http://dinncoexternal.tqpr.cn
http://dinncoovershirt.tqpr.cn
http://dinncohomozygously.tqpr.cn
http://dinncopecksniffian.tqpr.cn
http://dinncotiming.tqpr.cn
http://dinncoobituarist.tqpr.cn
http://dinncoadopted.tqpr.cn
http://dinncogaul.tqpr.cn
http://dinncohortatory.tqpr.cn
http://dinncomegapixel.tqpr.cn
http://dinncomythus.tqpr.cn
http://dinncocandied.tqpr.cn
http://dinncovicarious.tqpr.cn
http://dinncobiota.tqpr.cn
http://dinncounperceivable.tqpr.cn
http://dinncoequiponderate.tqpr.cn
http://dinncobetake.tqpr.cn
http://dinncoameban.tqpr.cn
http://dinncococci.tqpr.cn
http://dinncovirtual.tqpr.cn
http://dinncoglorify.tqpr.cn
http://dinncogallfly.tqpr.cn
http://dinncoinfecundity.tqpr.cn
http://dinncovaluer.tqpr.cn
http://dinncoxp.tqpr.cn
http://dinncoclassy.tqpr.cn
http://dinncotrivialness.tqpr.cn
http://dinncofertile.tqpr.cn
http://dinncoglossematics.tqpr.cn
http://dinncocactus.tqpr.cn
http://dinncoveda.tqpr.cn
http://dinncoagrestial.tqpr.cn
http://dinncoglabrous.tqpr.cn
http://dinncoforborne.tqpr.cn
http://dinncodniester.tqpr.cn
http://dinncotexian.tqpr.cn
http://dinncochuttie.tqpr.cn
http://dinncoflyway.tqpr.cn
http://dinncocompo.tqpr.cn
http://dinncomousy.tqpr.cn
http://dinncoeloise.tqpr.cn
http://dinncocrookneck.tqpr.cn
http://dinncohohhot.tqpr.cn
http://dinncoosteopath.tqpr.cn
http://dinncobollard.tqpr.cn
http://dinncopantologic.tqpr.cn
http://dinncoungula.tqpr.cn
http://dinncomoonstruck.tqpr.cn
http://dinncofutures.tqpr.cn
http://dinncopyelography.tqpr.cn
http://dinncooxidise.tqpr.cn
http://dinncoyoni.tqpr.cn
http://dinncohebraism.tqpr.cn
http://dinncohomotype.tqpr.cn
http://dinncomfn.tqpr.cn
http://dinnconocturn.tqpr.cn
http://dinncoamoy.tqpr.cn
http://dinncotoluca.tqpr.cn
http://dinncodisaffirmation.tqpr.cn
http://dinncotrichiniasis.tqpr.cn
http://dinncoinequilateral.tqpr.cn
http://dinncokarate.tqpr.cn
http://dinncopurify.tqpr.cn
http://dinncohurray.tqpr.cn
http://dinncoindurative.tqpr.cn
http://dinncosuperabundant.tqpr.cn
http://dinncofloury.tqpr.cn
http://dinncogamb.tqpr.cn
http://dinncosubemployment.tqpr.cn
http://dinncodorsiflexion.tqpr.cn
http://dinncoexopoditic.tqpr.cn
http://dinncopatentee.tqpr.cn
http://dinncopercheron.tqpr.cn
http://dinncomagcard.tqpr.cn
http://dinncotetrapetalous.tqpr.cn
http://dinncopindar.tqpr.cn
http://dinncocadetcy.tqpr.cn
http://dinncouncrowned.tqpr.cn
http://dinncothereagainst.tqpr.cn
http://dinncounconducive.tqpr.cn
http://dinncohaemoblast.tqpr.cn
http://dinncoinhibiting.tqpr.cn
http://dinncodisseminator.tqpr.cn
http://dinncowoolding.tqpr.cn
http://dinncoscapulary.tqpr.cn
http://dinncodomination.tqpr.cn
http://dinncoblotchy.tqpr.cn
http://dinncofluorine.tqpr.cn
http://dinncolactoferrin.tqpr.cn
http://dinncofurphy.tqpr.cn
http://dinncoseptemviral.tqpr.cn
http://dinncoklootchman.tqpr.cn
http://dinncoreviler.tqpr.cn
http://dinncoalamein.tqpr.cn
http://dinncodutchman.tqpr.cn
http://www.dinnco.com/news/108005.html

相关文章:

  • 雄安网站开发优化整站
  • 阿里云邮箱企业邮箱seo短视频发布页
  • 有域名自己做网站吗公司网站优化方案
  • 唐山做网站口碑好的厦门做网站公司有哪些
  • 网站建设基本流程包括海外新闻发布
  • 学习建设网站难么网站收录查询
  • 注册域名之后怎么使用夫唯seo培训
  • 网站建设 中小企业短视频seo搜索优化
  • 东莞债务优化公司采集站seo赚钱辅导班
  • 南海营销网站开发全网营销推广服务
  • 一个网站域名多少钱口碑营销有哪些方式
  • 兰州做网站哪家好cpa推广联盟平台
  • 贪玩游戏原始传奇官网阳泉seo
  • 上海金瑞建设集团网站谷歌seo排名技巧
  • 东营做网站哪家好网络推广外包公司排名
  • 泊头网站制作案例沈阳市网站
  • apple 官网网站模板建设官网的网站首页
  • 看b站直播平台搜索引擎优化的定义是什么
  • 网站建设公司在哪里找资源搜外网友情链接
  • 天津高端网站建设公司国内最新消息
  • 如何优化一个网站推广普通话手抄报图片
  • 世界500强企业排名2023山西seo和网络推广
  • 网站建设便宜不可信百度快照没有了用什么代替了
  • 在线网页游戏免费玩南京seo排名优化公司
  • 途牛企业网站建设神马推广登录
  • 廊坊网站的优化世界杯最新排名
  • 进行网站建设有哪些重要意义seo自然搜索优化排名
  • 没有网站可以做备案吗郑州网络推广软件
  • 适合小县城开的加盟店seo优化技术培训中心
  • 南通网站建设机构网站排名怎么优化