Python CGI: how to retrieve variables passed by URL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sean Berry

    Python CGI: how to retrieve variables passed by URL

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

    How do I gather this value?

    Thanks in advance.


  • Sean Berry

    #2
    Re: Python CGI: how to retrieve variables passed by URL

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

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

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



    "Sean Berry" <sean_berry@cox .net> wrote in message
    news:hU1ic.8673 0$U83.37750@fed 1read03...[color=blue]
    > If I go to my cgi python script with
    > localhost/cgi-bin/script-name.cgi?variab le=value
    >
    > How do I gather this value?
    >
    > Thanks in advance.
    >
    >[/color]


    Comment

    • Heiko Wundram

      #3
      Re: Python CGI: how to retrieve variables passed by URL

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

      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.

      Comment

      Working...