Environment variables in cgi

Anders M Eriksson anders.eriksson at morateknikutveckling.se
Wed Feb 2 06:22:21 EST 2000


On Wed, 02 Feb 2000 10:41:06 +0100, Maurizio Manetti
<giannozzo at arca.net> wrote:

>I'm newbie with python. I'm trying to make some little cgi program.

Me too!!

>I have this problem:
>In my little script I import the powerful module cgi, then I ty to
>access the dictionary cgi.environ but it seems not to exist! Why?

I don't think that there is a dictionary called environ in the cgi
module. As far as I can figure out (with the help of my friends) the
way to do this is to use the FieldStorage function to create an
dictionary which includes all cgi fields, both from your form and from
the shell.

import cgi

cgidata = cgi.FieldStorage()

Now the variable cgidata will be a dictionary with all the fields. If
you have an form with a field called 'username' then you can get the
username like this:

uname = cgidata['username']

now the variable uname will contain the value of the field username.

To see which fields that are 'imported' you could use the function
test()

cgi.test()

It will then print out an HTML page with all the fields that the cgi
module can get.

// Anders
-- 
English isn't my first or second language, 
so errors or anything that you find offending is not there on 
purpose it's just due to the translation.



More information about the Python-list mailing list