Receiving Data from an HTML File : Form : CGI Web PYTHON TUTORIALS


PYTHON TUTORIALS » CGI Web » Form »

 

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/htmln
<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



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo CGI Web
» Form