Passing values to another script using CGI

Fuzzyman fuzzyman at gmail.com
Mon Mar 14 05:48:20 EST 2005


Hello Mike,

Mike Wimpe wrote:
> Without creating a form, how do i pass a value to another script?
>
> I would like to pass:
>
> group = "Oranges"
>
> to another script or at least just 'group' and initialize it in the
> first script.
>

Do you want to pass it *from* a CGI script or *two* a CGI script.

If you are calling a remote script (and if you're not it's an odd
question !) then you can just build the query manually.

(When you hit submit the browser builds a request query from the values
in the form. All you need to do is generate the query yoruself instead
of having hte browser do it).

In order to do this you need to understand how parameters are passed to
a CGI script. It can be done either using the 'GET' method or the
'POST' method and the values need to be properly escaped.

The urllib.urlencode function will take a dictionary of parameters and
values and return a query string. If you use urllib2.urlopen to fetch
http://www.someserver.com/cgi-bin/yourscript.py + '?' + query_string
then your CGI will be called with the relevant parameters.

Regards,

Fuzzy
http://www.voidspace.org.uk/python/cgi.shtml


> script1:
> '''
> <html>
> <form method=POST action=script2.py>
> <input type=submit yada yada>
> group = "Oranges"
> '''
>
> script2:
> 
> print ''' Oh you like '''+group+'''.'''
> 
> thanks,
> 
> Mike




More information about the Python-list mailing list