少年乘勇气,百战过乌孙。这篇文章主要讲述django给app返回接口列表, 流式分页相关的知识,希望能为你提供帮助。
# -*- coding: utf-8 -*- __author__ = ‘YongCong Wu‘ # @Time: 2019/12/30 12:45 # @Email:: 1922878025@qq.comclass Pagenation(object):def __init__(self,data_list,page,per_data_num = 10): ‘‘‘ 初始化 :param data_list: 所有数据列表 :param page: 当前要查看的列表页 :param per_data_num: 每页默认要显示几条 ‘‘‘ self.data_list = data_list self.page = page self.per_data_num = per_data_num@property def start(self): ‘‘‘ 计算引索的起始位置 :return: ‘‘‘ return (self.page - 1) * self.per_data_num@property def end(self): ‘‘‘ 计算引索的结束位置 :return: ‘‘‘ return self.page * self.per_data_numdef show(self): ‘‘‘ 切片取数据,展示对应分页的结果 :return: ‘‘‘ result = self.data_list[self.start:self.end] data = https://www.songbingjia.com/android/[] for row in result: data.append(row) return data
def articleNews(request, question_id): result = {} data = https://www.songbingjia.com/android/[] print(question_id) content_list = models.AriticeModel.objects.all() for i in content_list: data_dict = {} data_dict[‘image‘] = i.img_url data_dict[‘id‘] = i.id data_dict[‘post_title‘] = i.title data_dict[‘post_like‘] = 525 data_dict[‘category_name‘] = i.aritice_gjz data.append(data_dict)obj = pagetion.Pagenation(data, question_id) result[‘data‘] = obj.show() result[‘code‘] = 200 return JsonResponse(result)
【django给app返回接口列表, 流式分页】
推荐阅读
- 最简单的方法通过命令制作安卓签名文件证书并获取其 md5,可不安装软件
- android 使用人脸功能随处可用的方法
- call 和 apply
- Android Jetpack -- Lifecycles篇
- Android基础——隐式intent和intent过滤器
- django-腾讯paas-appengine阅读
- [record] 初入android
- Android基础知识再次理解
- android+spring boot 选择,上传,下载文件