# 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
相关文章
- 11-05python中查询数据库时fetchone()函数和fetchall()函数的区别
- 11-05使用jmeter在数据库中批量插入数据
- 11-05Python批量扫描服务器指定端口状态
- 11-05hadoop更改保存路径后,批量重启不能启动datanode(或者format以后不能启动datanode)
- 11-05Python3批量合并excel 格式xlsx和xls都行
- 11-05[Python Study Notes]批量将wold转换为pdf
- 11-05saltstack+python批量修改服务器密码
- 11-05python-excel-固定格式批量转化sql建表语句
- 11-05python批量重命名
- 11-05Python - 批量修改文件名