#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    Python not able to bind variable to html


    I have HTML based webform for collecting the information from user, and posting it to python httpRequest Handler,

    I am trying achieve the autofilling of fields in the webform.
    In this webform there are fields related to network settings, which should be auto filled

    To do that I am reading a file(net.ini) through python which has these network information in key pair values
    for eg: ipaddress=10.10.10.1
    gateway= 10.10.10.254
    dns=8.8.8.8 etc

    while python can read file based on key pair value and is assigned to a variable. But when I map these variable in html it is simply not working, instead of variable value it is showing the variable name itself, though the variable has some value.

    here is the screen shot of what is happening




    This is the piece of code that reads file and does variable value mapping

    ########## FOR AUTOFILLING OF NETWORK INFO INTO THE FIELDS OF FORM.HTM PAGE
    ###########################################################################
    net_info=""
    if os.path.exists("/local/ipas/net.ini"):
    getSecondIfaddr()
    net_info = open("./form.htm",'r').read()
    ini_string=open("/local/ipas/net.ini","r").read()
    for e in ini_string.split("\n"):
    if e.startswith('ipaddress'):
    netip = e.split('=')[1]
    print "%s" %netip
    fields_map = {
    'ini_string' : ini_string,
    'netip' : netip,
    }

    s = net_info % fields_map
    ct = 'Content-type','text/html'

    Can someone please help me out with this issue, not sure where I am doing it wrong.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    506
    Rep Power
    33
    What is the purpose of this line
    Code:
             s = net_info % fields_map
    net_info is the data from the file and you don't use "s" anywhere. You should also test the len() of netip to make sure you found data. You can not write a dictionary to a file but can pickle it.

    Quoted to show indentation
    Code:
    ########## FOR AUTOFILLING OF NETWORK INFO INTO THE FIELDS OF FORM.HTM PAGE
    ###########################################################################       
          net_info=""
          if os.path.exists("/local/ipas/net.ini"):
             getSecondIfaddr()
             net_info = open("./form.htm",'r').read()
             ini_string=open("/local/ipas/net.ini","r").read()
             for e in ini_string.split("\n"):
               if e.startswith('ipaddress'):
                 netip = e.split('=')[1]
             print "%s" %netip
             fields_map = {
                 'ini_string' : ini_string,
                 'netip' : netip,
                 }
    
             s = net_info % fields_map
             ct = 'Content-type','text/html'
    Last edited by dwblas; November 9th, 2013 at 12:20 AM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0
    Well thankyou for the reply.

IMN logo majestic logo threadwatch logo seochat tools logo