Skip to main content

DeerU Api

DeerU接口扩展,返回json数据

目录

安装

  1. 使用pip安装:

    pip install deeru-api
  2. 把app添加到 deeru/settings_local.py 中:

    CUSTOM_APPS = [
        'deeru_api.apps.DeerUApiConfig'
    ]
  3. 在 urls_local.py 中自定义你的接口url:

    urlpatterns = [
        path('api/', include('deer_api.urls')),
    ]

数据格式

基础格式

接口返回的数据必带有一个 code ,code 为0表示正常,不为0会有一个 msg 为错误提示,

基本格式如下:

{
    'code' : 0,
    'msg'  : 'xx',

    # 其他数据
    ...
}

其他数据格式

接口为Article、Category等设计了一个通用数据格式,接口中返回的每种类型的数据格式都是一样的。

  • Article:

    {
        'id': 12,
        'content': 'xxx', # 正文
        'image': 'http://xx', # 封面图片
        'summary': 'xxx', # 简介
        'title': 'title',
        'created_time': '2018-03-12T11:23:00',
        'modified_time': '2018-03-12T11:23:00',
    }
  • ArticleMeta:

    {
        'id': 12, # 注意,这个是article_meta的id
        'article_id': 12
        'comment_num': 3
        'read_num': 333
    }
  • Category:

    {
        'id': 1,
        'name': 'xxx',
        'father_id': -1, # 父类别id,-1表示无父类别
        'm_order': 4, # 用于排序
    
    }
  • CategoryMeta:

    {
        'article_num': 10,
    
    }
  • Tag:

    {
        'id': 12,
        'name': 'xxx',
    }
  • TagMeta:

    {
        'article_num': 10,
    
    }
  • Comment:

    {
        # 下面所说的评论和回复其实是一个东西,两个名字只是为了方便区别
    
        # 评论 -- 对文章的评论叫评论
        # 回复 -- 对评论的回复叫回复 ,对回复的回复也叫回复
    
        'id': 1,
        'content': 'xxx',
        'email': '123@123.com',
        'nickname': 'xx',
        'article_id': 12, # 哪个文章下的评论
        'type': 201 , # 201: 评论 ;202: 回复
    
        # 关于 root_id, to_id具体解释可查看DeerU源码中 app.app_models.content_model.Comment 下的注释,里面有详细说明
    
        'to_id': -1, # 回复的评论id。对文章评论时,这一项无意义。
        'root_id': -1, # 根评论id。对文章评论时,这一项无意义;对评论回复时就是评论的id,对回复回复时,是最早的那条评论id
    }
  • FlatPage:

    {
        'id': 12,
        'content': 'xxx', # 正文
        'title': 'title',
        'created_time': '2018-03-12T11:23:00',
        'modified_time': '2018-03-12T11:23:00',
    }

接口

获取config

获取配置中设置为到context的所有配置

  • url : app_config

  • 请求方法 : GET

  • 参数 :

  • 返回值:

    {
        'code':0,
        'config':{
            'global_value':{ ... },
            'top_ico':{ ... },
            'top_menu':{ ... },
            'common_config':{ ... },
    
            ...
        }
    }

获取文章

  • url : article/<int:article_id>

  • 请求方法 : GET

  • 参数 :

  • 返回值:

    {
        'code':0,
        'article': Article , # Article类型,结构参照上面
        'article_meta': ArticleMeta ,
        'category': [ Category, Category ],
        'last_article': Article,
        'next_article': Article,
        'tags': [ Tag, Tag ],
    
    }

获取文章列表

  • url : article_list

  • 请求方法 : GET

  • 参数 :

    • page : 页数,默认:1

    • pre_page : 一页多少文章,默认:7

    • filter_type : 筛选类型,可选项如下:

      • article : 默认,筛选所有文章

      • category : 筛选分类下文章

      • tag : 筛选标签下文章

    • category_id : 筛选分类下文章时指定分类id

    • tag_id : 筛选标签下文章时指定标签id

  • 返回值:

    {
        'code':0,
        'article_list': [
                {
                    'article': Article ,
                    'article_meta': ArticleMeta ,
                    'category': [ Category, Category ],
                    'tags': [ Tag, Tag ],
                },
    
                { ... }
         ],
    
        'paginator': {
                'end_index': 4 , # 最大页码
                'current_page_num': 1 ,# 当前页码
        }
    
    }

获取分类

  • url : category/<int:category_id>

  • 请求方法 : GET

  • 参数 :

  • 返回值:

    {
        'code':0,
        'category': Category,
        'category_meta': CategoryMeta,
    
    }

获取分类列表

  • url : category_list

  • 请求方法 : GET

  • 参数 :

  • 返回值:

    {
        'code':0,
        'category_list': [
    
                {
                    'category': Category,
                    'category_meta': CategoryMeta
                },
    
                {...}
        ]
    
    }

获取分类树

返回按父子结构整理后的分类list

  • url : category_tree

  • 请求方法 : GET

  • 参数 :

  • 返回值:

    {
        'code':0,
        'category_tree': [
    
                {
                    'category': Category,
                    'category_meta': CategoryMeta
                    'children':[
    
                        {
                            'category': Category,
                            'category_meta': CategoryMeta
                            'children':[ ... ]
                        },
                    ]
                },
    
                {...}
        ]
    
    }

获取标签

  • url : tag/<int:tag_id>

  • 请求方法 : GET

  • 参数 :

  • 返回值:

    {
        'code':0,
        'tag': Tag,
        'tag_meta': TagMeta,
    
    }

获取标签列表

  • url : tag_list

  • 请求方法 : GET

  • 参数 :

  • 返回值:

    {
        'code':0,
        'tag_list': [
    
                {
                    'tag': Tag,
                    'tag_meta': TagMeta,
                },
    
                {...}
        ]
    
    }

创建评论

创建评论,需要注意 POST 请求需要在 cookies 里添加 csrftoken

  • url : comment/create

  • 请求方法 : POST

  • 参数 :

    • content : 内容

    • email : 可不填

    • nickname : nickname

    • type : type,可选项如下:

      • 201 : 对文章评论

      • 202 : 对评论评论

    • to_id : 回复的评论id,具体说明参见 Comment 结构说明,以及DeerU源码

    • root_id : 根评论id,具体说明参见 Comment 结构说明,以及DeerU源码

  • 返回值:

    {
        'code':0
    }

获取文章的评论列表

返回父子结构的评论list

  • url : comment_list

  • 请求方法 : GET

  • 参数 :

    • article_id : 文章id

  • 返回值:

    {
        # 注意:children里不会再有children
    
        'code':0,
        'comment_list': [
    
                {
                    'comment': Comment,
                    'children': [
                            {
                                'comment': Comment,
                                'to_nickname': 'xx'
                            },
    
                            { ... }
                    ],
                },
    
                {...}
        ]
    
    }

获取单页面

  • url : flatpage/<path:url>

  • 请求方法 : GET

  • 参数 :

  • 返回值:

    {
        'code':0,
        'flatpage': FlatPage
    
    }

Metadata

Release files for deeru-api 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for deeru-api 1.0.2
File Size Uploaded Provenance Actions
deeru-api-1.0.2.tar.gz 22.6 kB Without provenance Details for deeru-api-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for deeru-api 1.0.2
File Interpreter ABI Platform Actions
deeru_api-1.0.2-py3-none-any.whl Python 3 none any Details for deeru_api-1.0.2-py3-none-any.whl

Total release size: 30.4 kB

Release files / deeru-api-1.0.2.tar.gz

Download URL deeru-api-1.0.2.tar.gz
Size 22.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c7fb58ab1589fe7b73ccc267e2eadf43bb4bad6c8ce4abe91dccc7974191c348
BLAKE2b-256 checksum
How to use checksums
faa8f4211950e5b75cd13d8e31a0506ed2f881421e9868bf3b51cfb9544ebd8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / deeru_api-1.0.2-py3-none-any.whl

Download URL deeru_api-1.0.2-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e225fd6b49fab3946caab578e077c3045e0287c57c6f24b9327ee4c25afe3c6
BLAKE2b-256 checksum
How to use checksums
e26d81481ed877bac4f0c47a112477e2c823b06e2b07fb2182df48aeee2faac6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for deeru-api 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page