1. Technology

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


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] 
      [do something else] 
  1. About.com
  2. Technology
  3. Python
  4. Web Development
  5. Python and HTML - Creating HTML and XHTML Pages in Python - Feeding Options To Your Python Script

©2014 About.com. All rights reserved.