Python CGI: how to retrieve variables passed by URL

Discussion in 'Python' started by Sean Berry, Apr 23, 2004.

  1. Sean Berry

    Sean Berry Guest

    If I go to my cgi python script with
    localhost/cgi-bin/script-name.cgi?variable=value

    How do I gather this value?

    Thanks in advance.
     
    Sean Berry, Apr 23, 2004
    #1
    1. Advertising

  2. Sean Berry

    Sean Berry Guest

    This may help, but not sure if there is a better, built in way.

    print os.environ["QUERY_STRING"].split("=")[1]

    prints value if I use localhost/cgi-bin/script-name.cgi?variable=value and
    this will work... but is there a better way?



    "Sean Berry" <> wrote in message
    news:hU1ic.86730$U83.37750@fed1read03...
    > If I go to my cgi python script with
    > localhost/cgi-bin/script-name.cgi?variable=value
    >
    > How do I gather this value?
    >
    > Thanks in advance.
    >
    >
     
    Sean Berry, Apr 23, 2004
    #2
    1. Advertising

  3. Am Freitag 23 April 2004 07:42 schrieb Sean Berry:
    > print os.environ["QUERY_STRING"].split("=")[1]
    >
    > prints value if I use localhost/cgi-bin/script-name.cgi?variable=value and
    > this will work... but is there a better way?


    Start python, and type import cgi and then help(cgi). The cgi module should
    take care of what you need perfectly. If the docstrings aren't enough to get
    you started, go to www.python.org -> Documentation -> Global Module Index and
    check the documentation of the cgi module there.

    HTH!

    Heiko.
     
    Heiko Wundram, Apr 23, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dee
    Replies:
    9
    Views:
    515
    Joseph Byrns
    Apr 15, 2005
  2. Fernie
    Replies:
    10
    Views:
    5,934
    Jukka K. Korpela
    Dec 21, 2004
  3. Anand
    Replies:
    2
    Views:
    906
    Anand
    Sep 11, 2003
  4. Geoff
    Replies:
    4
    Views:
    1,148
    GIMME
    Dec 4, 2003
  5. shumsta
    Replies:
    1
    Views:
    274
    Fabian Pilkowski
    Jul 22, 2005
Loading...

Share This Page