0

There is an HTML file which takes first name and last name in it. Now I want that data to be into the file using python. There's something called CGI script, but I am not getting to how should I write. Moreover I am an newbie. So sorry for asking silly question

here's my HTML code:

<html>
    <head>
    <title>INFORMATION</title>
    </head>
      <body>
        <form action = "/cgi-bin/test.py" method = "post">
            FirstName:
            <input type = "text" name = "firstname" /><br>
            LastName:
            <input type = "text" name = "lastname" /><br>

            <input type = "submit" name = "submit "value = "SUBMIT">
            <input type = "reset" name = "reset" value = "RESET">
            </form>
       </body>
</html>

My python code which i wrote is:

#!usr/bin/python

form = web.input()
print form.firstname
print form.lastname
john john
  • 127
  • 2
  • 6
  • 13

2 Answers2

0

Change the form action to point to the URL of the Python script you want the data sent to. Then implement your Python script to get the POST variables "firstname" and "lastname". There's an example here: How are POST and GET variables handled in Python?.

Community
  • 1
  • 1
smartfuse
  • 51
  • 6
0

You need to setup a server that redirects requests to a python script, change the url of the form action to point to that script and then actually write a python script that does what you want.

Have you tried looking into a Web Development framework like Flask? That might do what you want.

wdh
  • 1,612
  • 12
  • 16
  • Ok, cool. Follow the instructions in [this question](http://stackoverflow.com/questions/464040/how-are-post-and-get-variables-handled-in-python) then. – wdh Oct 24 '13 at 09:55
  • its not working so ...when i run my web server with html page submit click it shows no file found – john john Oct 24 '13 at 09:57