[mod_python] passing parameters from index() to POST method

Graham Dumpleton graham.dumpleton at gmail.com
Wed Mar 3 19:41:11 EST 2010


On 4 March 2010 11:27, Rob Fowler <legal at mianos.com> wrote:
> Although that works fine and will call my post function, the apache server
> 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):
>    do stuff
>
> def handler(req):
>    If req.method == "POST":
>        gen_keys(specificDictionary )
>    else:
>        specificDictionary = readDictionary("/blah/specialdict.txt", "rule
> 1")
>        req.write("""<HTML ... <FORM value="form" action="handler.py/handler"
> method="post"> etc
>    return 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):
>>        If req.method == "POST":
>>                gen_keys(parameters here)
>>        else:
>>                normal handler code
>>        retrun apache.OK
>>
>>
>>
>> On Mar 3, 2010, at 12:28 PM, Rob Fowler wrote:
>>
>>
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>



More information about the Mod_python mailing list