class UserInfoView(Resource):标签:xiaoming,goods,flask,升序,query,序列化,page,GoodsModel From: https://www.cnblogs.com/cstn/p/16710580.html
# @marshal_with(field)
def get(self):
# daming = User('daming',40,None)
# xiaoming = User('xiaoming',16,daming)
#
# return marshal(xiaoming,{
# 'name':fields.String,
# 'age':fields.Integer,
# 'baba':UserFields
# })
# print(xiaoming.name)
# print(xiaoming.age)
# print(xiaoming.baba)
# goods = GoodsModel.query.first()
# print(goods)
# goods = GoodsModel.query.all()
# jjj = marshal(goods,field)
# # print(jjj)
#
# return jsonify({
# 'code':200,
# 'msg':'获取数据成功',
# 'data':jjj
# })
# goods_list = GoodsModel.query.all()
goods = GoodsModel.query.filter(GoodsModel.sname=='哈哈铁凳子').first()
# goods = GoodsModel.query.filter_by(sname = '哈哈铁凳子').first()
# goods = GoodsModel.query.offset(1).limit(1).all()
# page = 1
# page_size = 10
# goods = GoodsModel.query.offset((page - 1) * page_size).limit(page_size).all()
# # 假设 一页10条数据
# # 那么 第3页数据,应该是多少条到多少条 21 - 30
# goods = GoodsModel.query.order_by(GoodsModel.price).all() # 升序
# goods = GoodsModel.query.order_by(GoodsModel.price.asc()).all() # 升序
goods = GoodsModel.query.order_by(GoodsModel.price.desc()).all() # 降序
return marshal(goods,field)
总结:分页: 如果page = 1 ,1-1=0,数据就是1-10的数据,如果page=2,2-1=1,隔掉第一页的1-10的数据,就是11-20的数据,依次类推,
序列化器:序列化器比较麻烦,不如写for循环简单,所以还是不写序列化器比较好。
排序:字符串也可以排序!
自行解决一个需要安装cryptography包的错误,其实只需运行数据库即可