Skip to content

Latest commit

 

History

History
88 lines (44 loc) · 1.7 KB

10.1django_restful4.md

File metadata and controls

88 lines (44 loc) · 1.7 KB

restful使用指南3

Auth: 王海飞

Data:2018-05-04

Email:779598160@qq.com

github:https://github.com/coco369/knowledge

1. 分页

修改settings.py配置文件,增加分页的配置信息

图

结果:

图

注意:在结果在data对应的value值中,有一个count的key,表示返回数据有3条,next表示下一个的url,previous表示上一页的url。

2. 过滤

修改settings.py配置文件,增加filter过滤的信息

2.1 安装过滤的库

pip install django-filter

2.2 配置settings.py的信息

配置DEFAULT_FILTER_BACKENDS

图

2.3 views中指定filter_class

图

2.4 编写filter_class过滤信息

图

2.5 实现方法

2.5.1 查询学生的姓名中包含王的学生

使用filter_class进行过滤筛选:

http://127.0.0.1:8080/stu/student/?name=王

不使用filter_class进行筛选:

图

2.5.2 查询学生的创建时间在2018年1月1号到2018年6月1号的学生信息

使用filter_class进行过滤筛选:

http://127.0.0.1:8080/stu/student/?create_min=2018-02-01&create_max_max=2018-0-01

不使用filter_class进行筛选:

图

2.5.3 查询状态为休学的学生信息
http://127.0.0.1:8080/stu/student/?status=LEAVE_SCH
2.5.4 查询所有的学生,按照id从大到小排序

图

2.6 拓展

图