Re: Get parameters from URL using CGI

2006-02-19 Thread John Zenger
import cgi
import cgitb; cgitb.enable()  # Optional; for debugging only

print Content-Type: text/html
print

f = cgi.FieldStorage()
for i in f.keys():
print p,i,:,f[i].value


abcd wrote:
 i want to create a CGI script which simply prints out values given via
 the URL (such as when a GET is performed).
 
 So if I have a script named, foo.cgi and I access it by going to:
 
 http://www.somesite.com/cgi-bin/foo.cgi?name=johnage=90
 
 I want foo.cgi to print out:
 name: john
 age: 90
 
 
 how do i get the values from the URL like that?
 
 thanks
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Get parameters from URL using CGI

2006-02-18 Thread abcd
i want to create a CGI script which simply prints out values given via
the URL (such as when a GET is performed).

So if I have a script named, foo.cgi and I access it by going to:

http://www.somesite.com/cgi-bin/foo.cgi?name=johnage=90

I want foo.cgi to print out:
name: john
age: 90


how do i get the values from the URL like that?

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Get parameters from URL using CGI

2006-02-18 Thread Ian Leitch
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

abcd wrote:
 i want to create a CGI script which simply prints out values given via
 the URL (such as when a GET is performed).
 
 So if I have a script named, foo.cgi and I access it by going to:
 
 http://www.somesite.com/cgi-bin/foo.cgi?name=johnage=90
 
 I want foo.cgi to print out:
 name: john
 age: 90
 
 
 how do i get the values from the URL like that?
 
 thanks

 from urlparse import urlparse
 dict([n for n in [i.split('=') for i in
urlparse('http://www.somesite.com/cgi-bin/foo.cgi?name=johnage=90')[4].split('')]])
{'age': '90', 'name': 'john'}


-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFD94zrefZ4eWAXRGIRAlEhAJ49x7kaIe/VcU5DUbt8bv9tQCNrmQCfWOED
tmkTISLqzIKDz2c4mfR6+k8=
=OMOX
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Get parameters from URL using CGI

2006-02-18 Thread abcd
Ian Leitch wrote:
  from urlparse import urlparse
  dict([n for n in [i.split('=') for i in
 urlparse('http://www.somesite.com/cgi-bin/foo.cgi?name=johnage=90')[4].split('')]])
 {'age': '90', 'name': 'john'}


Ian,  thanks for the reply, but that is not what I need to do.  Inside
foo.cgi how can I parse out the values given in the URL?

So if you visit: http://www.somesite.com/cgi-bin/foo.cgi?valA=1valB=2
.I want the script, foo.cgi to print out the parameters and their
values.  It's dynamic so the values are url wont be the same all the
time.  How do i get the URL from the script?  does this make sense?

So I'm thinking foo.cgi will look like
[code]
url = getTheFullURL()
parse(url)

def parse(url):
# parse the parameter names and values
[/code]

-- 
http://mail.python.org/mailman/listinfo/python-list