Miguel Marques
miguel at yorku.ca
Mon Sep 11 07:55:33 EST 2000
On Mon, 11 Sep 2000 01:28:36 -0400, peter at wl.vg wrote: > I am just learning Python and am trying to learn how to use it for > online applications. Sorry for my ignorance, but I usually develop in > perl. I can't find documentation that describes how to do this. I have > pieced this together, but it doesn't work. > > from mod_python import apache > import cgi > > > def handler(req): > > > len = int(req.headers_in["content-length"]) > form_data = cgi.parse_qs(req.read(len)) > > req.send_http_header() > req.write("This is from the form: "+form_data['name']+"!") > return apache.OK > Here's snippet of some test code I've used... import cgi from mod_python import apache def handler(req): form = {} req.content_type = "text/plain" req.send_http_header() if req.headers_in.has_key("content-length"): len = int(req.headers_in["content-length"]) if len > 0: data = req.read(len) form = cgi.parse_qs(data) for l,y in form.items(): req.write(l + ": " + y[0] + "\n") else: if (req.args): form = cgi.parse_qs(req.args) for l,y in form.items(): req.write(l + ": " + y[0] + "\n") return apache.OK Hope it helps... Miguel C. Miguel Marques, York University, Computing & Communications Services e-mail: miguel at yorku.ca, voice: (416)736-2100x22684, fax: (416)736-5830
|