2013-08-25 45 views
0

我開始在本地主機上使用Mako模板引擎。但是,每次我想選擇模板時,都需要輸入模板的完整位置(例如:c:/Users/username/Desktop/xampp/htdocs/blog/scripts/templates/index.html')。我想改變它,例如每次只輸入'scripts/templates/index.html'或類似的東西。更改根目錄Python和mod_wsgi

任何建議如何做到這一點?

回答

0

使用mako的TemplateLookup類。舉例來說,使用文檔中的示例:

from mako.template import Template 
from mako.lookup import TemplateLookup 

template_path = "c:/Users/username/Desktop/xampp/htdocs/blog" 
mylookup = TemplateLookup(directories=[path]) 

def serve_template(templatename, **kwargs): 
    templatename = "scripts/templates/index.html" 
    mytemplate = mylookup.get_template(templatename) 
    print mytemplate.render(**kwargs)