2

我正在使用带有 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.titleparent.title都不管用。如何从初始调用中传递变量?

4

1 回答 1

0

为了使用呈现的变量 - 你使用它们而${ title }不是$( title )

于 2017-03-21T12:22:43.050 回答