1. Home
  2. Computing & Technology
  3. Python

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

By Al Lukaszewski, About.com

2 of 6

Creating HTML Output

First, creating a new HTML document is simply a matter of putting the relevant HTML as the argument of a print command:

print '''
content-type: text/html

<html>
<head>
<title> This is the title </title>
</head>
<body>
This is the body.
</body>
</html>
'''

Recall that triple quotes in Python tell it to print what follows verbatim. It disregards any character sequences for strings, etc. If you need to represent variable data, default to using the standard single quotation mark method.

x = "variable"
print "This is a %s." %(x)

With this information, one can create a bevy of HTML pages with variable content very quickly and automagically.

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

  1. Introduction
  2. Creating HTML Output
  3. Creating New Forms
  4. Feeding Options To Your Script
  5. Feeding Options From the Command Line
  6. Concluding Comments

2 of 6

Explore Python

More from About.com

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

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

All rights reserved.