标签:customer 函数 oca ddr sheet list word moni response
可以先读取表格的内容,再通过下面的方式进行迭代 from monitor.models import * import xlrd data = xlrd.open_workbook(‘/home/mypj/ip.xls‘) table = data.sheet_by_name(‘MPLS‘) table = data.sheet_by_name(‘DIA‘) t = table.row_values iplist =[Ipinfo_model( order_id=t(i)[0], ipaddr=t(i)[1], mask=t(i)[2], customer=t(i)[3], addr=t(i)[4], line_no=t(i)[5], PE=t(i)[6], PE_port=t(i)[7], SW=t(i)[8], SW_port=t(i)[9], BW=t(i)[10], AS_no=t(i)[11], Vender=t(i)[13], baoxiu=t(i)[14] ) for i in range(1,table.nrows)] Ipinfo_model.objects.bulk_create(iplist) data = xlrd.open_workbook(‘/home/mypj/vrf.xls‘) table = data.sheet_by_name(‘VRF‘) t = table.row_values iplist =[Vrf_model( customer=t(i)[0], vrf_name=t(i)[1], vrf_rd=t(i)[2], yongtu=t(i)[3] ) for i in range(1,table.nrows)] Vrf_model.objects.bulk_create(iplist) ping iplist =[Ping_model( Line=t(i)[0], Hostname=t(i)[1], port=t(i)[2], Local_ip=t(i)[3], Dest_ip=t(i)[4], Vrf=t(i)[5], ) for i in range(1,table.nrows)] Ping_model.objects.bulk_create(iplist) host iplist =[host_model( host=t(i)[0], hostip=t(i)[1], ) for i in range(1,table.nrows)] host_model.objects.bulk_create(iplist) host_model
用户认证:
#用户登录测试 from django.contrib.auth.decorators import login_required from django.contrib import auth
在Views加入以下代码:
#这里登录 def account_login(request): username = request.POST.get(‘username‘) password = request.POST.get(‘password‘) #登录 user = auth.authenticate(username=username,password=password) #如果登录不为空 if user is not None: auth.login(request,user) #转到特定页面 return HttpResponseRedirect(‘/ipinfo/‘) else: return render_to_response(‘index.html‘,{‘err‘:‘wrong username or password!‘},context_instance=RequestContext(request)) #退出的页面 def logout(request): #退出登录 auth.logout(request) return HttpResponseRedirect(‘/‘) #如果想要有所有页面上启用登录检测,未登录就不允许访问,直接访问登录页面 #在每个方法前加这个修饰函数 @login_required def ipinfo(request): XXXXXX
标签:customer 函数 oca ddr sheet list word moni response
原文地址:http://www.cnblogs.com/syother/p/6732804.html