Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change a web2py view on the fly?

Tags:

view

web2py

Can you change the view being used by web2py in the controller? Ideally I'd be interested in doing something like:

response.view = 'NewViewName'

like image 349
Chris Avatar asked Feb 21 '23 22:02

Chris


1 Answers

You've got it exactly, though be sure to include the relative path to the view within the /views folder. So, if you have /views/default/other_view.html, you can do:

response.view = 'default/other_view.html'

You can also directly render any view:

def myfunc():
    context = dict(...)
    return response.render('default/other_view.html', context)

See here and here.

like image 88
Anthony Avatar answered Mar 23 '23 12:03

Anthony