标签:logs range userinfo 获取 view nbsp 字典 _id set
1 ##====================================CBA操作============================ 2 3 # class geting(View): 4 # def dispatch(self, request, *args, **kwargs): 5 # print(‘before‘) 6 # obj = super(geting,self).dispatch(request,*args,**kwargs) 7 # print(‘after‘) 8 # return obj 9 # 10 # def get(self,request): 11 # print(‘get.get‘) 12 # return render(request,‘geting.html‘) 13 # 14 # def post(self,request): 15 # print(‘get.post‘) 16 # print(request.POST.get(‘user‘)) 17 # return HttpResponse(‘get.post‘)
1 ##===================================FBA操作============================ 2 def get(request): 3 print(2222) 4 return HttpResponse(‘is get‘) 5 6 ‘‘‘ 7 get 查 8 post 创建 9 put 更新 10 delete 删除 11 12 常用传值方式 13 ‘‘‘
1 ##=====================================ORM操作========================================= 2 def gets(request): 3 pass 4 # for row in range(300): 5 # name=‘root‘+str(row) 6 # models.UserInfo.objects.create(name=name,age=18,ut_id=1) 7 # models.UserInfo.objects.create(name="方少伟",age=18,ut_id=1), 8 # models.UserInfo.objects.create(name="刘庚",age=18,ut_id=2), 9 # models.UserInfo.objects.create(name="尤勤兵",age=18,ut_id=3), 10 # models.UserInfo.objects.create(name="王哲",age=18,ut_id=1), 11 # models.UserInfo.objects.create(name="陈涛",age=18,ut_id=2), 12 # models.UserInfo.objects.create(name="小白",age=18,ut_id=3), 13 14 # models.UserType.objects.create(title="普通用户") 15 # models.UserType.objects.create(title="二逼用户") 16 # models.UserType.objects.create(title="牛逼用户") 17 # return HttpResponse(‘ok‘) 18 19 ##========================================正向查找=============================================== 20 # result = models.UserInfo.objects.all() 21 # for obj in result: 22 # print(obj.name,obj.age,obj.ut_id,obj.ut.title) 23 ##打印obj对象的名字,对象的年龄,对象的外键,ut设置外键的列就是相当于ut表对应的主键(现在拿到就是ut那个表可以拿ut对应的一行所有内容) 24 # result = models.UserInfo.objects.all().first() 25 # ##获取表中所有的行但只是拿第一个对象,也就是第一行 26 # print(result.name,result.age,result.ut) 27 28 ##========================================反向查找=============================================== 29 # obj = models.UserType.objects.all().last() 30 # print(‘用户类型‘,obj) 31 # for row in obj.userinfo_set.all(): 32 # print(row.name,row.age) 33 34 35 36 ##========================================对象查看及连表=============================================== 37 # models.UserInfo.objects.all() 38 #查看UserIinfo表的所有行 39 # models.UserInfo.objects.filter(id=2) 40 ##查看UserInfo表id等于2的哪一行内容 41 # result = models.UserInfo.objects.all() 42 ##通过此方式返回一个列表中存放的是对象(object) 43 # for row in result: 44 # print(row.name,row.id,row.age,row.ut.title) 45 ##以是对象的方式进行连表 46 47 ##========================================字典查看及连表=============================================== 48 # models.UserInfo.objects.all() 49 ## 查看表的所有行 50 # models.UserInfo.objects.filter(id=1) 51 ##查看表的id是1的行 52 # result=models.UserInfo.objects.all().values(‘id‘,‘name‘,‘ut__title‘) 53 ##通过此方式连表返回个列表,列表中存放的是字典对象(dict) 54 # for row in result: 55 # print(row) 56 57 ##========================================元组查看及连表=============================================== 58 # models.UserInfo.objects.all() 59 ## 查看表的所有行 60 # models.UserInfo.objects.filter(id=2) 61 ##查看表的id是2的行 62 # result=models.UserInfo.objects.all().values_list(‘id‘,‘name‘,‘ut__title‘) 63 ##通过此方式连表返回个列表,列表中存放的是元组对象(tuple) 64 # for row in result: 65 # print(row)
标签:logs range userinfo 获取 view nbsp 字典 _id set
原文地址:http://www.cnblogs.com/guobaoyuan/p/7083001.html