Passing parameters via URL

Colin Meeks colin at programmedintegration.com
Sat Oct 21 14:13:26 EDT 2000


Thanks Harald, solution was bang on.  Problem now solved.

Colin

"harald " <harald at skumbad.nu> wrote in message
news:mailman.972084415.4749.python-list at python.org...
Colin Meeks:
 +
 | I've written some code that produces a web page.  I have the same code
 | replicated several times, with small changes that I use throughout a
site.
 | How can I bring these all into one program so I can make a call like
 |
 |     http://www.xyz.com/program.py?dothis
 |
 | or
 |
 |     http://www.xyz.com.program.py?dothat
 |
 | and have the Python program determine what to do when it receives either
 | dothis or dothat.
 +

if that is all you want to do, the easiest way would probably be:

 import os

 if os.environ["QUERY_STRING"] == "dothis":
         dothis()
 elif os.environ["QUERY_STRING"] == "dothat":
         dothat()
..etc..

you probably want to use the cgi module if you want
to pass more variables to the script, like
http://www.xyz.com/program.py?do=this&usefulvariable=23

/harald       bada at skumbad.nu       http://bada.skumbad.nu/

Hail Eris! All Hail Discordia!
Don't let THEM immanentize the Eschaton.






More information about the Python-list mailing list