Thanks Anthony !
On Thursday, March 29, 2012 2:31:02 PM UTC+13, Anthony wrote: > > locals() returns a dictionary including all the variables in the local > function, so it is exactly equivalent to dict(grid=grid) in this case. See > http://docs.python.org/library/functions.html#locals. In general, though, > you should probably explicitly return just the variables you need to pass > to the view. > > Anthony > > On Wednesday, March 28, 2012 8:41:19 PM UTC-4, Andrew wrote: >> >> Hi , >> >> I've been wondering about the use of return locals() in the Forms chapter >> of the book, particularly with grids >> def manage_users(): >> grid = SQLFORM.grid(db.auth_user) >> return locals() >> >> Elsewhere in the book use see something like this for forms return dict( >> form=form) >> Would return dict(grid=grid) have given the same result as above? I know >> a dict is required to automatically use a view with the a/c/f.html naming >> standard, but what does locals() use ? >> I think it would help to clarify this in the book? >> >> Core chapter has: >> >> *Return a dictionary for a view*: >> >> def index(): return dict(key='value') >> >> *Return all local variables*: >> >> def index(): return locals() >> >> >> and also this: >> >> When an action returns a dictionary, web2py looks for a view with the name >> >> 1. >> >> [controller]/[function].[extension] >> >> and executes it. >> Thanks >> Andrew >> >

