Mega Code Archive

 
Categories / Python Tutorial / CGI Web
 

Receiving Data from an HTML File

< HTML> <form action="cgi-bin/action.py">  <paragraph>Enter your first name:</paragraph>  <input type="text" name="firstname" size="40">  <paragraph>Enter your last name:</paragraph> <input type="text" name="lastname" size="40">  <input type="submit">  <input type="reset"> </form> </HTML> File: action.py #!c:/Python25/python import cgi reshtml = """Content-Type: text/html\n <html>  <head><title>Hello</title></head>  <body>   <h1>Welcome to a Python script!</h1>   <paragraph>You are identified as: %s</paragraph>  </body> </html>""" form = cgi.FieldStorage() lastname = form['lastname'].value firstname = form['firstname'].value message = firstname + " " + lastname print reshtml % message