Can you show a more concrete example? The benefit of the generic actions and views is not quite clear. If you want to re-use the same action/function to return slightly different data, can't you use URL args or vars to specify what is requested and return the appropriate data based on those values?
Also, note that you can always re-use a view by specifying response.view (i.e., this allows you to change from the default [controller]/[function].[extension] view to any view you want). Anthony On Monday, October 15, 2012 10:33:14 AM UTC-4, apinho wrote: > > Hi, > > I started with web2py a few weeks ago, writing some very simple apps. I > noticed that I was constantly repeating myself in the following steps : > Write a controller to fetch the data > Write a view to present data. > > So, I made generic controllers and views, which I later call using this > schema : > > User request : http://myserver/myapp/mymodel_list > > In CONTROLLERS/DEFAULT.PY : > def mymodel_list(): > return generic_list() > > In MODELS/GENERIC.PY : > def generic_list(): > # Do all work here, get mydata, pagination, etc... > return dict(mydata) > > In VIEWS/DEFAULT/MYMODEL_LIST.HTML : > {{extend 'generic_list.html'}} > > In VIEWS/GENERIC_LIST.HTML > {{extend 'layout.html'}} > {{include}} > <!-- Do all representation of mydata --> > > This works well for me, cause I only have to deal with 4/5 controller and > views (generic_list, generic_read, generic_add, generic_edit). > > One question though : > For every model I have to create all the functions : > def mymodel_read(): > return generic_read() > def mymodel_list(): > return generic_list() > etc... > .. and I also have to create all the views : > mymodel_list.html : > {{extend 'generic_list'}} > mymodel_list.read : > {{extend 'generic_read'}} > ...etc > > I believe there must be a way to avoid creating these views and these > controllers, through the use of routes, or something. > > Someone care to guide me to do this ? > > > > > > --