cgi parameters

python at python at
Thu Dec 28 18:07:50 CET 2000

> I need to pass index parameter to script executed by post method (via
> form)

> <form action="newpost.cgi?index=1" method="post">

The way that you are trying to pass a parameter will not work for forms;
although it will work for links such as:

<a href="newpost.cgi?index=1">Click Me!</a>

To pass parameters via a form, you need to include the parameter withing an
<input> tag. If You do not want to allow the client to modify the value of the
parameter you need to use a 'hidden' input tag. For example:

<form action="newpost.cgi method="get">
  <input type=hidden name='index' value='1'>
  <input type=submit>

Of course, just because the parameters are hidden does not mean that a web
user that knows HTML could not rewrite the page and submit their own values.
So you still need to validate the data.

Now that should solve your problem. However, what if you really need to use
the method that you were originally attempting? Retarget your form action to
the following short python script:

import cgi
print cgi.test()

This will display a wealth of information about the shell and web server
environment. (And this little script will come in handy for debugging many
form/CGI problems.) I ran this script on my system and after examining the
results I found the following entry:


Within a python script this could be accessed via:

import os
request_uri = os.environ['REQUEST_URI']

It is important to note that while your server may not call this value
"REQUEST_URI". Or it may provide an environmental variable
containing just "?index=1" which would simplify parsing a bit.

Lee A. Joramo                      ljoramo at
The Nickel Want Ads      
Internet Manager                   970-242-5555

Sent via

More information about the Python-list mailing list