Passing values to another script using CGI

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Wimpe

    #1

    Passing values to another script using CGI

    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

  • Fuzzyman

    #2
    Re: Passing values to another script using CGI

    Hello Mike,

    Mike Wimpe wrote:[color=blue]
    > 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.
    >[/color]

    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.urlencod e 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

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

    Comment

    Working...