def ershouzuh1h2(): pgnum = request.args.get('page', 1) fangs = TSecondSource.query.filter( or_(TSecondSource.hu_type.startswith('3室'), TSecondSource.hu_type.startswith('2室')), TSecondSource.sell_rent == '租').all() if fangs: pages = -(-len(fangs) // 20) # 向上取整,算出总页数 print('总页为', pages) print('您访问的页码为', pgnum) if int(pgnum) > pages: # 访问的页码不存在 return jsonify({'state': 0, 'msg': '您访问的资源不存在'}) elif 1 <= int(pgnum) < pages: #判断页数的范围 res = to_json(fangs[(int(pgnum) - 1) * 20:int(pgnum) * 20]) elif pages == 1: #如果只有一页,直接返回 res = to_json(fangs) elif pages == int(pgnum): res = to_json(fangs[(int(pgnum) - 1) * 20:]) #返回最后一页数据 data = [] for ret in res: del ret['broker'] del ret['broker_id'] del ret['ld']['l_pwd'] data.append(ret) return jsonify({'state': 1, 'msg': '返回数据成功', 'data': data}) else: return jsonify({'state': 0, 'msg': '您访问的资源不存在'})
def xinfangp1(): pgnum = request.args.get('page', 1) fangs = TSource.query.filter(TSource.price_s.__le__(9000)).all() if fangs: pages = -(-len(fangs) // 20) # 向上取整,算出总页数 print('总页为', pages) print('您访问的页码为', pgnum) if int(pgnum) > pages: # 访问的页码不存在 return jsonify({'state': 0, 'msg': '您访问的资源不存在'}) elif 1 <= int(pgnum) < pages: #判断页数的范围 res = to_json(fangs[(int(pgnum) - 1) * 20:int(pgnum) * 20]) elif pages == 1: #如果只有一页,直接返回 res = to_json(fangs) elif pages == int(pgnum): res = to_json(fangs[(int(pgnum) - 1) * 20:]) #返回最后一页数据 data = [] for ret in res: del ret['broker']['b_pwd'] data.append(ret) return jsonify({'state': 1, 'msg': '返回数据成功', 'data': data}) else: return jsonify({'state': 0, 'msg': '您访问的资源不存在'})