By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,053 Members | 1,595 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,053 IT Pros & Developers. It's quick & easy.

Passing values to another script using CGI

P: n/a
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.

script1:
'''
<html>
<form method=POST action=script2.py>
<input type=submit yada yada>
group = "Oranges"
'''

script2:

print ''' Oh you like '''+group+'''.'''

thanks,

Mike

Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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


Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.