入门
我们依然遵循的Django开发思路,API的开发两同需要views.py和url.py进行配合。
我们将所需要的api整合到API APP中
api/urls.py
path("soogorlogin", never_cache(sgusers.soogorfoclogin)),
path("index_view", article.index_view),
path("publishcontent", never_cache(article.publishcontent)),
path("addartcon", never_cache(article.add_article_con)),#加新内容
path("addartbaike", never_cache(article.add_article_baike)),
path("article_get", never_cache(article.article_get)), #获取文章详情
path("article_list", never_cache(article.article_list)), #API文章列表
path("do_tags", never_cache(article.do_tags)),#处理原来没有tag多对多字段的内容
path("ajax_val", never_cache(sgdataviews.ajax_val)),
path("add_baike", never_cache(baikeviews.add_baike)),
path("baikeAlias", never_cache(baikeviews.baikeAlias)),#获得百科别名
path("link_baike", never_cache(baikeviews.link_baike)),
path("add_dsj", never_cache(baikeviews.add_dsj)),
path("remove_article_link", never_cache(article.remove_article_link)),
path("link_article", never_cache(article.link_article)),
path("article_addbaikelink", never_cache(article.article_addbaikelink)),#给文件加上百科链接
path("getaddbaikelinklogs", never_cache(article.getaddbaikelinklogs)),#获取添加链接的日志
path("article_removebaikelink", never_cache(article.article_removebaikelink)),#移除文章内百度的链接
path("getremovebaikelinklogs", never_cache(article.getremovebaikelinklogs)),#获取移除链接的日志
path("get_status_num", never_cache(article.get_status_num)),
#静态操作
path("articlestatic", never_cache(article.articlestatic)), #生成所有文章静态
path("articlestaticlogs", never_cache(article.articlestaticlogs)),#获取静态操作的的日志
path("removearticlestatic", never_cache(article.removearticlestatic)),#移除静态文件
下面我们以"addartcon"这个API的使用做为示范
提交方式:POST
http(s)://域名/api/addartcon
字段 | 类型 | 描述 |
---|---|---|
title | str | 标题 |
content | str | 正文内容 |
status | int |
99:审核, 0:待审,1:草稿,3:回收站 |
node | int | 栏目节点ID |
Intro | str | 简介 |
Tags | str | 标签、关键词 |
Editer | int | 编辑用户ID |
该API需要验证所以我们还需要加个APPID 和APIKEY
这样整个addartcon的data为:
{'appid':'xxxxxx',
'apikey':'xxxxxxxxxxxxxxxxxxxxxx',
'title': 'title',
'content': 'content',
'status':1,
'node':2,
'Intro':'des',
'Tags':'keyword',
'Editer':1}
该API为post提交,所以我们在浏览器中访问链接是提交不了的。
addartcon成功返回:
{
"status": "BS.200",
"msg": "publish article success."
}
失败返回:
{
"status": "BS.400",
"msg": "please check param."
}
但是有的API是get提交的
比如说“publishcontent”
介绍:根据发布推送中的设置,将指定状态的文章变为发布状态
提交方式:get
http(s)://域名/api/publishcontent
字段 | 类型 | 描述 |
---|---|---|
code | str | 在后台“发布推送”中设置的值 |
例如我们通过设置后的URL为:http(s)://域名/api/publishcontent?code=e3r34342
当我们使用的时候就可以直接访问这个API进行触发
我们可以将这个链接加入到宝塔的计划任务,设置为访问URL,频率定为5分钟,这样我们就可以将我们的草稿中的文章每5分钟发布一条