1. Home
  2. Computing & Technology
  3. Python

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

From , former About.com Guide

4 of 6

Feeding Options To Your Script

If, however, you prefer to feed options to your scripts, this is easily done as well. Using the above example, one simply need to add to the action line the command line argument prefaced with a question mark. If one wants to test for a string argument of '1', the line might look like this:

<form action="./test.cgi?1" method="post">

In the subsequent CGI script 'test.cgi', one would then have an if loop to test whether the argument is '1' or not.

x = sys.argv[1]

if x == '1':
     [do something]
else:
     [do something else]

Explore Python
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

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

  1. Home
  2. Computing & Technology
  3. Python
  4. Web Development
  5. Python and HTML - Creating HTML and XHTML Pages in Python - Feeding Options To Your Python Script

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

All rights reserved.