Cherrypy的Mako工具
CherrypyMako的Python项目详细描述
CherrypyMako是一个cherrypy插件,它在cherrypy中提供mako模板引擎作为工具。
示例:
demo.py:
import os.path import cherrypy import CherrypyMako import datetime CherrypyMako.setup() root_dir = os.path.abspath( os.path.dirname(__file__)) class Root(object): @cherrypy.expose @cherrypy.tools.mako(filename='index.html') def index(self): return {'currentTime':datetime.datetime.now()} _cp_config={ 'global':{ 'server.socket_host' : '0.0.0.0', 'server.socket_port' : 1919, 'tools.mako.directories' : [os.path.join(root_dir,'templates')], }, } if __name__ == '__main__': cherrypy.quickstart(Root(), '', config=_cp_config)
index.html:
<html> <head> <title>Cherrypy Mako Tool Demo</title> </head> <body> ${currentTime} </body> </html>