【问题标题】:Is it possible to change a web2py view on the fly?是否可以动态更改 web2py 视图?
【发布时间】:2012-01-05 22:22:14
【问题描述】:

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

response.view = 'NewViewName'

【问题讨论】:

    标签: view web2py


    【解决方案1】:

    您已经完全明白了,但请确保在 /views 文件夹中包含视图的相对路径。所以,如果你有 /views/default/other_view.html,你可以这样做:

    response.view = 'default/other_view.html'
    

    你也可以直接渲染任何视图:

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

    参见herehere

    【讨论】:

      猜你喜欢
      • 2017-08-29
      • 2020-02-04
      • 1970-01-01
      • 2017-07-24
      • 2017-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多