web2py book understanding

4 views
Skip to first unread message

dederocks

unread,
Aug 19, 2010, 2:33:31 AM8/19/10
to web2py-users
Hello,

I want to give web2py a try, and so experiment as I follow the online
web2py book.
Chapter 3, section 'Postbacks', code snipet:

if not request.function=='first' and not session.visitor_name:
redirect(URL('first'))


Does not appear to work as expected. request.function always returns
'second'. Is this normal? My understanding was that request.function
should return the caller's url?
In other words, changing the above code to:

if not request.function=='first':
redirect(URL('first'))

Always sends you to the first page.

Sincerely,

Andre

DenesL

unread,
Aug 19, 2010, 6:55:55 AM8/19/10
to web2py-users
Hi Andre,

request.function has the name of the function called
i.e. the function part in
http://ipadr:port/app/controller/function

If request.function is always 'second' it means you are always calling
http://yourserverip:port/yourapp/default/second

Hope this helps,
Denes

dederocks

unread,
Aug 19, 2010, 7:58:37 AM8/19/10
to web2py-users
Hi Denes,

Thanks a lot for the clarification.
That said, the >not request.function=='first'< part of the if
statement seems therefore useless, since this code is run only when
requesting the 'second' function.
Andre


On 19 août, 12:55, DenesL <denes1...@yahoo.ca> wrote:
> Hi Andre,
>
> request.function has the name of the function called
> i.e. the function part inhttp://ipadr:port/app/controller/function
>
> If request.function is always 'second' it means you are always callinghttp://yourserverip:port/yourapp/default/second

DenesL

unread,
Aug 19, 2010, 10:13:32 AM8/19/10
to web2py-users
You are right, the text just above the given code sample

if not request.function=='first' and not session.visitor_name:
redirect(URL('first'))

was changed for the 3ed and it is wrong, it should read:
"... (outside the second function)."

instead of:
"... (inside the second function)."

Good catch!

Denes
Reply all
Reply to author
Forward
0 new messages