# Create your views here. #-*-coding:utf-8-*- from django.template import loader,Context,Template from django.http import HttpResponse from models import User from django.shortcuts import render_to_response def index(req): #批量查询出数据 startId =1 endId=100 numId = (endId-startId)+1 numi=numId/20 addnumId= numId%20 for i in range(numi): Idstart=startId Idend=i*20 user =User.objects.filter(pk__gt=0).filter(pk__lt=5) print user.values() if len(user)>0: print 'fff' else: print 'kong' #print user data1 =[] data=[] for key in user: data1.append(key.name) data1.append(key.age) data1.append(key.sex) # print data1 data.append(data1) data1=[] #批量保存 # for user in range data : # user =user #data=[['李四',12,'女'],['王五',56,'男'],['赵六',25,'男']] stu=User() for user in data: print user #User.objects.create(name=user[0],age=user[1],sex=user[2]) #User.objects.create(user) # user.save() #print data return render_to_response('index.html',{''}) def instance(startId,endId): #startId =1 #endId=100 numId= (endId-startId)+1 numi=numId/20 addnumId=numId%20 if addnumId >0: numi+=1 for i in range(numi): if i==0: Idstart=startId Idend =(i+1)*20+startId print Idstart,Idend elif i==(numi-1): Idstart=startId+(i*20) Idend =endId print Idstart,Idend else: Idstart=startId+(i*20) Idend =(i+1)*20+startId print Idstart,Idend