Hi candide and welcome aboard,
returning a dict from a web2py function means that you want to call a
view with the same name to render the output, as opposed to returning
a string which will be the final output.
In your views you can use the dict keys as variables to display
information, for example using the {{=key}} template language
construct. So if you have:
def index():
...
return dict(x=10)
then a <controller>/index view will be called, and if you have a
{{=x}} in it that will output '10'. You can also use x in loops,
conditions, or any python construct that you require e.g.
{{for i in range(0,x):}}
{{if x=='5':}}
You can also return more complex objects such as functions.
That is the beauty of it, all of python is available to you.
Note that views are python programs, just normally disguised as html
code with some extraneous code enclosed in double braces.
Hope this helps,
Denes
On Jan 29, 8:39 am, candide2023 <[email protected]> wrote:
> hi, I am new here, in python and web2py as well. I was thinking about
> to get involved in web programming, I started with php (studied about
> 2 weeks) and then tried django (about 1 day) and now web2py(about 2
> weeks) I am going through the manual. Anyways, there is one poing that
> I didnt get.
>
> Why do we have dict's. and why do we always need to use it as:
>
> def index()
> ...
>
> return dict (a=b)
>
> this is where I didnt get.
>
> Thanks for the reply.
>
> Best,
--
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en.