Some of the information here may be outdated, please check the book instead
[edit]

Question

This how i understand the relationship: I create a controller:

 def index(): return dict(mylist = [1,2,3])

then i ihave to create a view with the same name i.e app/views/controller/index.html in which i refer to the server variable list

What about if i want to use the same controller index for an other view say my_app/an_other_index.html Can this be done or i have to create an other controller an_other_index and copy exactly the same code from the controller index()

My question is can the data computed in one controller used by many views?

Answer

Yes. Examples:

def index(): return dict(mylist=[1,2,3])

def other(): return index()

index will be rendered by app/views/controller/index.html and other by app/views/controller/other.html. You can also have them share a view:

def yet_other():
    response.view=request.controller+'/index.html'
    return index()

and yet another will use index as controller and index.html as view.

© 2008-2010 by Massimo Di Pierro - All rights reserved - Powered by web2py - design derived from a theme by the earlybird
The content of this book is released under the Artistic License 2.0 - Modified content cannot be reproduced.