我正在使用带有 Mako 模板的 CherryPy。我正在尝试弄清楚如何从初始调用中传递参数(在此示例中title
):
class Landing(object):
def index(self):
tmpl = lookup.get_template("index.html")
return tmpl.render(title="Hello World")
index.exposed = True
至index.html
:
<%inherit file="base.html"/>
<%def name="title()">$(title)</%def>
this is the body content
然后到继承的base.html
模板:
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>$(self.title())</title>
</head>
<body>
<h1>$(parent.title())</h1>
${self.body()}
</body>
</html>
我试过了self.title
,parent.title
都不管用。如何从初始调用中传递变量?