Oups you're right.

Now I remember what I didn't understand at this point, and probably
what the OP was expecting.

The book says :

"
Note that if the "second" action is ever called before a visitor name
is set, it will display "Hello anonymous" because session.visitor_name
returns None.
"

What the OP expected (and what I expected last week) was that by using
the form on the "first" url without entering anything and submitting
it it should display "hello anonymous".

However it's not the case and it's not what the book refers to
(whereas it's pretty close, thus the misunderstanding).

BUT, and it's probably what the book tries to say :

If you DIRECTLY try to acces the url "/second" without EVER having
filled the first form with a name, you will get "Hello Anonymous".

Of course you can probably "reproduce" this behavior after having
submitted a name on the first url by clearing your browser's cache/
cookies or trying to access the second url with another browser.

Cheers,


On 31 jan, 17:25, Anthony <abasta...@gmail.com> wrote:
> > I'm pretty sure the first should be like this :
>
> > **********
>
> > def first():
> >     if request.vars.visitor_name:
> >         session.visitor_name = request.vars.visitor_name
> >         redirect(URL('second'))
> >     return dict(form=form)
>
> > **********
>
> > NOTICE THE return dict(form=form), I think it's what is missing at
> > this step in the book (one page later it's corrected with the
> > FORM(INPUT()) form creation technic.
>
> No, in that particular example, the form is not defined in the controller
> at all. If you do "return dict(form=form)", you will get an error, because
> "form" has not been defined. In this case, the form is defined in the view.
> The first() function simply receives the form post and checks whether
> "visitor_name" is one of the variables in the post -- otherwise, it simply
> returns the first.html view, which includes the empty form.
>
> Anthony

Reply via email to