Passing values to another script using CGI

M

Mike Wimpe

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
 
F

Fuzzyman

Hello Mike,

Mike said:
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
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top