Passing parameters via URL

harald harald at skumbad.nu
Fri Oct 20 19:33:49 EDT 2000


 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