See http://web2py.com/books/default/chapter/29/4#Workflow:

"The view sees every variable defined in the models as well as those in the 
dictionary returned by the action, but does not see global variables 
defined in the controller."

web2py builds an environment and runs the models in that environment (which 
may then add objects to it). It then creates a copy of the environment 
before running the controller, and after running the controller, it adds 
the items returned in the dictionary by the controller to the 
pre-controller copy of the environment, which is where the view is 
executed. You can see this 
here: http://code.google.com/p/web2py/source/browse/gluon/main.py#200

Anthony

On Thursday, January 5, 2012 9:03:03 AM UTC-5, Peter O wrote:
>
> Hihi,
>
> I am baffled by what I see between Example 1 and 2.
>
> It may be a good case to improve my understanding of the run-time 
> environment of web2py.
>
> Thanks in advance for any comments.
>
> VIEW: (test.html)
>
> <html>  <body>
> {{=globals().get('t1', False)}}
>  </body> </html>
>
> CONTROLLER:
>
> == Example 1 ==
>
> def test():
>     global t1
>     t1 = True
>     return dict() # the browser show 'False'. I was expecting 'True'
>
> == Example 2 ==
>
> def test():
>     global t1
>     t1 = True
>
>     response.render('default/test.html', globals() ) #the return is 
> discarded
>
>     return dict() # the browser show 'True'. I was expecting the same 
> result as Example 1.
>
>
>
>
>
>

Reply via email to