I too am a beginner, but here is my two ha'p'orth... On Jul 24, 5:01 am, Jared Stunn <jsmatr...@gmail.com> wrote: > I know this is really basic but I dont understand. Can somebody please > explain what is happening in the excerpt below. I am doing chapter 3 > of the documentation found > here:http://www.web2py.com/book/default/chapter/03#Postbacks > > Here is my general understanding: > > 1) It appears that we are returning an empty dictionary which > typically should contain a message to be passed through to a view. But > none is provided.
Correct - often a dict is returned but for this example it is not necessary. > > 2) Is a layout with a form that directs to the controller "second" > that returns an empty dictionary. Correct > > 3) here we have a variable in head 1 that contains > "=request.vars.visitor_name" in the second view. The doc does explain > what request is or does as well as vars. So: When the user presses submit on form 1, the html causes a) a response to go to the server with a request for an action called second (because of the form action) b) a variable visitor_name='your response' to go as part of the http response The magic of web2py causes the second controller to be called in response to the action requested, and it also sets a request.vars variable which includes the http query variables including visitor_name populated with 'your response'. That variable is available to the second view. > > What is request and its function? What is vars and its function? What > do the dots in between them mean or do? How does "visitor_name" get > passed through to the second view without being passed through one of > the default controllers? Chapter 4 has a whole section about request which explains the dot notation and how it gets passed through. > > Here is the excerpt: > > 1) Write the corresponding actions in the default controller: > > def first(): > return dict() > > def second(): > return dict() > > 2) Then create a view "default/first.html" for the first action: > > {{extend 'layout.html'}} > What is your name? > <form action="second"> > <input name="visitor_name" /> > <input type="submit" /> > </form> > > 3) Finally, create a view "default/second.html" for the second action: > > {{extend 'layout.html'}} > <h1>Hello {{=request.vars.visitor_name}}</h1> > > Thank you very much. I am beginner who just switched over from Django > after hearing so many good things about the community and framework.