在Pyramid中使用Mako模板与Google App Engine

4 投票
1 回答
1672 浏览
提问于 2025-04-16 10:16

在使用Pyramid和mod_wsgi的时候,如果想要使用mako模板,只需要在development.ini文件中添加这一行:

mako.directories = house:templates

不过,在Google App Engine上使用Pyramid时,没有development.ini这个文件,所以我遇到了以下错误:

File "appengine-monkey/pyramidapp/app/lib/python/pyramid-1.0a9-py2.5.egg/pyramid/mako_templating.py", line 74, in renderer_factory
'Mako template used without a ``mako.directories`` setting')
ConfigurationError: Mako template used without a ``mako.directories`` setting

有没有什么办法可以传递这个环境变量呢?

1 个回答

9

我在pylons-devel的邮件列表上发现了这个信息。想说把答案发到这里。

解决这个问题的方法是把它作为一个设置传递给Configurator。所以在__init__.py文件中做如下修改:

config = Configurator(settings={'mako.directories':['house:templates']}) 

撰写回答