1. Home
  2. Computing & Technology
  3. Python

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

From Al Lukaszewski, for About.com

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" .

Explore Python
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Python
  4. Web Development
  5. Python and HTML - Creating HTML and XHTML Pages in Python - Creating New Forms

©2009 About.com, a part of The New York Times Company.

All rights reserved.