是否可以动态更改web2py视图?

Chr*_*ris 4 web2py view

你能改变控制器中web2py使用的视图吗?理想情况下,我有兴趣做以下事情:

response.view ='NewViewName'

Ant*_*ony 8

虽然确保在/ views文件夹中包含视图的相对路径,但您确实已经完成了它.因此,如果你有/views/default/other_view.html,你可以这样做:

response.view = 'default/other_view.html'
Run Code Online (Sandbox Code Playgroud)

您还可以直接渲染任何视图:

def myfunc():
    context = dict(...)
    return response.render('default/other_view.html', context)
Run Code Online (Sandbox Code Playgroud)

看到这里这里.