加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 使用weby将多个模板彼此嵌套在一起

发布时间:2020-12-20 13:35:31 所属栏目:Python 来源:网络整理
导读:我使用webpy建立了一个网站. 我的主页名为layout.html.我将foo1.html加载到布局中 $def with (content)htmlhead titleFoo/title/headbody$:content/body/html 里面的内容是foo1.html div Hello /div 是否可以更改foo1.html以加载其他网页: $def with (secon
我使用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>

解决方法

只需将渲染定义为模板全局

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()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读