Python webpy:如何覆盖基本模板的内容?
我将webpy与基本模板一起使用Python webpy:如何覆盖基本模板的内容?,python,templates,overriding,web.py,Python,Templates,Overriding,Web.py,我将webpy与基本模板一起使用 render = web.template.render(basedir + 'templates/', base='layout', globals=globals_vars_custom) 在layout.html中,我有如下内容: $def with (content) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-ht
render = web.template.render(basedir + 'templates/', base='layout', globals=globals_vars_custom)
在layout.html中,我有如下内容:
$def with (content)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>PAGE TITLE</title>
<!-- Some CSS and some javascript -->
</head>
<body>
$:content
</body>
</html>
这个基本模板适用于我90%的站点,但我有一个页面,需要在一些元标记中插入一些其他数据
我该怎么做?如何将模板放在可以轻松覆盖的结构中
谢谢 这比我想象的要容易: 可以在模板中创建变量: 在page.html中,您可以定义一个变量
$var title = 'specific title'
在base template layout.html中,可以调用变量:
$def with (content)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>$content.get("title","DEFAULT TITLE")</title>
<!-- Some CSS and some javascript -->
</head>
<body>
$:content
</body>
</html>
我希望这个答案也能对其他人有用