Python:在金字塔中访问Renderer Global

时间:2015-09-28 05:10:19

标签: python pyramid mako

我想从金字塔中的mako模板访问li > a:first-child + ul:before { border: 5px solid transparent; border-left: 8px solid #522; width: 0; height: 0; content: ""; display: inline-block; transform: rotate(90deg); margin-right: 5px; } 渲染器全局。我一直收到GMAPS_API_KEY未定义的错误:

GMAPS_API_KEY

我有3个文件(我省略了很多东西):

header.html中:

 ...
 File "views/header.html", line 10, in render_body
    <script src="https://maps.googleapis.com/maps/api/js?key=${GMAPS_API_KEY}&sensor=true"></script>
  File "/scratch/temp/venvs/py2.7.10/lib/python2.7/site-packages/mako/runtime.py", line 226, in __str__
    raise NameError("Undefined")
NameError: Undefined

map.mak:

 <script src="https://maps.googleapis.com/maps/api/js?key=${GMAPS_API_KEY}&sensor=true"></script> <!-- ERROR HERE -->

webapp.py

<%include file="header.html"/>

1 个答案:

答案 0 :(得分:1)

@subscriber要求您在包含该行config.scan()的包裹上调用@subscriber,或者您需要通过调用config.add_subscriber()替换您的装饰器,如Pyramid配置器的文档:http://docs.pylonsproject.org/projects/pyramid//en/latest/api/config.html#pyramid.config.Configurator.add_subscriber