我是python新手,目前正在嘗試使用mako模板。 我希望能夠從另一個html文件中獲取一個html文件並向其中添加一個模板。 比方說,我得到這個index.html
文件:從文件加載mako模板
<html>
<head>
<title>Hello</title>
</head>
<body>
<p>Hello, ${name}!</p>
</body>
</html>
這name.html
文件:
world
(是的,它只是裏面的字的世界)。 我想用name.html
文件的內容替換index.html
中的${name}
。 我已經能夠做到這一點沒有name.html
文件,通過陳述在Render方法什麼名字,使用下面的代碼:
@route(':filename')
def static_file(filename):
mylookup = TemplateLookup(directories=['html'])
mytemplate = mylookup.get_template('hello/index.html')
return mytemplate.render(name='world')
這顯然不適合大塊文本的有用。現在我只想加載name.html
中的文本,但還沒有找到辦法做到這一點。我應該嘗試什麼?