Re: passing parameters from index() to POST method
Graham Dumpleton <[email protected]> Thu, 4 Mar 2010 11:41:11 +1100
| Newsgroups | gmane.comp.python.mod_python |
|---|---|
| Message-ID | <[email protected]> |
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 ser= ver > 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. 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/specialdict= .txt", "rule > 1") > =A0 =A0 =A0 =A0req.write("""<HTML ... <FORM value=3D"form" action=3D"ha= ndler.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 >