我喜欢 StringTemplate 引擎,我喜欢 CherryPy 网络服务器,我知道它们可以集成。
谁做过?怎么办?
编辑:TurboGears 框架采用 CherryPy 网络服务器并捆绑其他相关组件,例如模板引擎、数据访问工具、JavaScript 工具包等。我对 MochiKit 感兴趣,需要 CherryPy,但我不想要任何其他组件模板引擎而不是 StringTemplate(架构很关键——我不想要另一个坏掉的/坏的模板引擎)。
因此,通过解决如何将 StringTemplate 与 TurboGears 集成来回答这个问题是可以接受的。
通过解决如何在 Google App Engine 中使用 CherryPy 和 StringTemplate 来回答这个问题也是可以接受的。
谢谢。
请您参考如下方法:
根据两者的教程,它看起来非常简单:
import stringtemplate
import cherrypy
class HelloWorld(object):
def index(self):
hello = stringtemplate.StringTemplate("Hello, $name$")
hello["name"] = "World"
return str(hello)
index.exposed = True
cherrypy.quickstart(HelloWorld())
您可能希望 CherryPy 函数在磁盘上的某个位置找到 StringTemplate,但总体思路是这样的。
Django 在概念上是相似的:url 被映射到 python 函数,而 python 函数通常构建一个上下文字典,使用该上下文对象渲染一个模板,并返回结果。
