On Feb 20, 2011, at 5:52 PM, Bruno Rocha wrote:
> I just made a test
>
> ################## controller ###############
>
> def wrapper():
> div = DIV('main wrapper',BR(),HR())
> def fun1():
> div = DIV('function2',BR(),HR())
> return locals()
>
> def fun2():
> div = DIV(' function 2',BR(),HR())
> return locals()
>
> return locals().get(request.args(0),locals())
>
> ############# controller ######################
>
> But that does not works
>
> when I request http://127.0.0.1:8000/testapp/default/wrapper I have the
> desired return as:
> <div><table><tr><td style="font-weight:bold;">div</td><td
> valign="top">:</td><td><div><div>main wrapper<br /><hr
> /></div></div></td></tr></table></div>
>
> But when I call http://127.0.0.1:8000/testapp/default/wrapper/fun1
> I got:
> <function funcao1 at 0x8777f0c> in HTML source
>
> How to evaluate the function ?
>
I think you need something more like:
if request.args(0) in locals():
return locals()[request.args(0)]()
return locals()
But I think for security reasons you might also test for request.args(0) in
['fun1', 'fun2']. Otherwise you could get some strange results.