Thanks for that explanation Bruno!

On Fri, Sep 17, 2010 at 7:11 AM, Bruno Rocha <[email protected]> wrote:

> Hi Tom
>
> The views in web2py should receive an serializable object to render it
> properly and "transform" in to html or something else (it is a very
> simplified explanation)
>
> You could return any serializable form the controller to the view:
>
> return 'Hello World'
> return ['1','2','3','four']
> return {'form':form}
> return{'name';'Tom'}
>
> But if you have an object created with any web2py helper(DIV, H1, TAG, UL,
> FORM, SQLFORM, etc), these creates serializable objects and should be sent
> to the views, and the best way is putting them inside a key-value
> dictionary.
>
> In Python the constructor dict() creates a dictionary, so doing
> dict(name='Tom') will create a dictionary and
> is the same as doing
> {'name':'Tom'}
>
> And this way is very useful when you need to do thongs like:
>
> def action():
>
>     myform = SQLFORM(......)
>     mydiv = DIV(.........)
>     myrows = db(.....).select(...)
>
>     return dict(form=myform,div=mydiv,rows=myrows)
>
> You can keep the reference in view as {{=form}}, {{=div}} and {{=rows}}
> and if you use the same view for various controllers, you just need to pass
> the key properly named, even if the objects has different names.
>
>
>
> 2010/9/16 Tom Campbell <[email protected]>
>
> New to Python & web2py. Searched for but could not find an explanation
>> of why so much code looks like:
>>
>>  return(form=form)
>>
>> What makes the assignment necessary?
>
>
>
>
> --
> Bruno Rocha
> http://rochacbruno.com.br
>

Reply via email to