Python CGI: how to retrieve variables passed by URL

S

Sean Berry

If I go to my cgi python script with
localhost/cgi-bin/script-name.cgi?variable=value

How do I gather this value?

Thanks in advance.
 
S

Sean Berry

This may help, but not sure if there is a better, built in way.

print os.environ["QUERY_STRING"].split("=")[1]

prints value if I use localhost/cgi-bin/script-name.cgi?variable=value and
this will work... but is there a better way?
 
H

Heiko Wundram

Am Freitag 23 April 2004 07:42 schrieb Sean Berry:
print os.environ["QUERY_STRING"].split("=")[1]

prints value if I use localhost/cgi-bin/script-name.cgi?variable=value and
this will work... but is there a better way?

Start python, and type import cgi and then help(cgi). The cgi module should
take care of what you need perfectly. If the docstrings aren't enough to get
you started, go to www.python.org -> Documentation -> Global Module Index and
check the documentation of the cgi module there.

HTH!

Heiko.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top