【问题标题】:Having multiple templates nested within each other using weby使用 weby 将多个模板相互嵌套
【发布时间】:2013-06-27 10:23:06
【问题描述】:

我已经使用 webpy 建立了一个网站。 我的主页名为 layout.html。我将 foo1.html 加载到布局中

$def with (content)
<html>
<head>
    <title>Foo</title>
</head>
<body>
$:content
</body>
</html>

而且里面的内容是foo1.html

<div> Hello </div>

是否可以更改 foo1.html 以同时加载另一个网页:

$def with (secondarycontent) 
<div> $:secondarycontent </div>

【问题讨论】:

    标签: python html templates web.py nested


    【解决方案1】:

    只需将render 定义为模板全局

    template_globals = {}
    render_partial = template.render(template_dir, globals=template_globals)
    render = template.render(template_dir, globals=template_globals,
                             base='layout')
    template_globals.update(render=render_partial)
    

    所以现在你可以从模板中调用它

    $:render.nested.template()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-23
      • 2011-08-03
      • 1970-01-01
      • 1970-01-01
      • 2011-11-24
      • 2014-05-23
      • 1970-01-01
      相关资源
      最近更新 更多