Re: passing parameters from index() to POST method
Graham Dumpleton <[email protected]> Thu, 4 Mar 2010 11:42:04 +1100
| Newsgroups | gmane.comp.python.mod_python |
|---|---|
| Message-ID | <[email protected]> |
On 4 March 2010 11:41, Graham Dumpleton <[email protected]> wrot= e: > On 4 March 2010 11:27, Rob Fowler <legal-1+f/[email protected]> wrote: >> Although that works fine and will call my post function, the apache se= rver >> calls the handler a second time so all the local variables are new. > > You better explain that a bit better. The handler function should not > be called multiple times for the same request. > > Dump out req.uri to see what URL is being accessed on each call. They > may actually be two separate requests. This can occur where a web > browser keeps requesting a favicon.ico and it doesn't exist. It could also occur if you have mucked up your Apache configuration and have listed the handler more than once using mod_python directives. Graham > Graham > >> What I >> want to do is pass a parameter to the 'POST' function (gen_keys here). >> For example, to change my example to the model suggested below: >> >> def gen_keys(dictionary): >> =A0 =A0do stuff >> >> def handler(req): >> =A0 =A0If req.method =3D=3D "POST": >> =A0 =A0 =A0 =A0gen_keys(specificDictionary ) >> =A0 =A0else: >> =A0 =A0 =A0 =A0specificDictionary =3D readDictionary("/blah/specialdic= t.txt", "rule >> 1") >> =A0 =A0 =A0 =A0req.write("""<HTML ... <FORM value=3D"form" action=3D"h= andler.py/handler" >> method=3D"post"> etc >> =A0 =A0return apache.OK >> >> Just use global variables? I don't like to use them in apache modules,= just >> the vibe. >> >> On 4/03/2010 12:30 AM, Martijn Moeling wrote: >>> >>> I'm nut excacly sure what you are trying to achieve. >>> >>> In your index.py handler you can: >>> >>> from wifikeys import gen_keys >>> >>> def handler(req): >>> =A0 =A0 =A0 =A0If req.method =3D=3D "POST": >>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0gen_keys(parameters here) >>> =A0 =A0 =A0 =A0else: >>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0normal handler code >>> =A0 =A0 =A0 =A0retrun apache.OK >>> >>> >>> >>> On Mar 3, 2010, at 12:28 PM, Rob Fowler wrote: >>> >>> >> >> _______________________________________________ >> Mod_python mailing list >> [email protected] >> http://mailman.modpython.org/mailman/listinfo/mod_python >> >