我似乎找不到任何关于在flask中使用cheetah模板引擎的信息。谁能告诉我google找不到的东西,或者告诉我如何在一个简单的flask应用中使用cheetah模板?
非常提前谢谢你。
发布于 2011-12-04 12:05:46
我不是猎豹或烧瓶专家,但我认为你不需要任何特别的支持来使它工作。在查看这两个示例时,我想到了这一点(它似乎对我来说很好)。
from flask import Flask
from Cheetah.Template import Template
mainTemplate = """
<html>
<head><title>$title</title></head>
<body><h1>$title</h1></body>
</html>"""
app = Flask(__name__)
@app.route('/')
def main_route():
return render(mainTemplate, {'title': 'Welcome to "/"!'})
def render(template, context):
"""Helper function to make template rendering less painful."""
return str(Template(template, namespaces=[context]))
if __name__ == "__main__":
app.run()https://stackoverflow.com/questions/8365244
复制相似问题