1. Computing

Creating HTML and XHTML Pages in Python - With and Without CGI

From , former About.com Guide

3 of 6

Creating New Forms

Creating new forms in the output is the same as creating forms in a standard HTML page.

 print ''' 
 content-type: text/html 
 
 <html> 
 <head> 
 <title> This is the title </title> 
 </head> 
 <body> 
 <br> 
 <form action="./test.cgi" method="post"> 
 <p> Name: <input type="text" name="name" id="name" value=""/></p> 
 <p> Street Address: <input type="text" name="st_address" id="st_address" value=""/></p> 
 <p> Town: <input type="text" name="town" id="town" value=""/></p> 
 <p> County: <input type="text" name="county" id="county" value=""/></p> 
 <p> Postcode: <input type="text" name="postcode" id="postcode" value=""/></p> 
 <p> Telephone: <input type="text" name="telephone" id="telephone" value=""/></p> 
 <p> Fax: <input type="text" name="fax" id="fax" value=""/></p> 
 <p> Email: <input type="text" name="email" id="email" value=""/></p> 
 <p> Website: <input type="text" name="website" id="website" value=""/></p> 
 <br> 
 <input type="submit" value="Submit" /> 
 </form> 
 </body> 
 </html> 
 ''' 
This code will create a form which receives contact information from the user and delivers it to 'test.cgi' for processing. From there, the data can be processed using the methods discussed in "Programming CGI With Python" .

  1. About.com
  2. Computing
  3. Python
  4. Web Development
  5. Python and HTML - Creating HTML and XHTML Pages in Python - Creating New Forms

©2013 About.com. All rights reserved.