Python Run script

Source: Internet
Author: User

The contents of the table can be read first and then iterated from monitor.models import *import xlrddata = Xlrd.open_workbook ('/home/mypj/ip.xls ') Table = Data.sheet_by_name (' MPLS ') Table = Data.sheet_by_name (' DIA ') t = table.row_valuesiplist =[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) [ten], as_no=t (i) [one], vender=t (i) [[], Baoxiu=t (i) [+]) 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) pingiplist =[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) hostiplist =[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 

User authentication:

#用户登录测试from django.contrib.auth.decorators import login_requiredfrom django.contrib Import auth

Add the following code to the 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)) # Page to exit Def logout (Request): #退出登录    auth.logout (Request)    return  httpresponseredirect ('/') # If you want to have all the pages enabled for login detection, do not log on to allow access, direct access to the login page # before each method add this modifier @login_required def ipinfo (request): XXXXXX


Python Run script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.