我正在尝试将PyPugJs与金字塔一起使用。
在我的__init.py
内,我有这个
config.include('pypugjs.ext.pyramid')
在views.py
内,
@view_defaults(renderer='json')
class St2Views:
"""docstring for St2Views"""
def __init__(self, request):
super(St2Views, self).__init__()
self.request = request
@view_config(route_name='hello')
def hello(self):
session = self.request.session
return Response('<body><h1>Hello</h1></body>')
@view_config(route_name='home')
def home(self):
return {
'a': 'b'
}
@view_config(route_name='index', renderer='index.pug')
def index(self):
return {}
尝试转到index
路线
Traceback (most recent call last):
File "z:\eels\dev\st2\env\lib\site-packages\pyramid_mako\__init__.py", line 148, in __call__
result = template.render_unicode(**system)
File "z:\eels\dev\st2\env\lib\site-packages\mako\template.py", line 454, in render_unicode
as_unicode=True)
File "z:\eels\dev\st2\env\lib\site-packages\mako\runtime.py", line 829, in _render
**_kwargs_for_callable(callable_, data))
File "z:\eels\dev\st2\env\lib\site-packages\mako\runtime.py", line 864, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "z:\eels\dev\st2\env\lib\site-packages\mako\runtime.py", line 890, in _exec_template
callable_(context, *args, **kwargs)
File "z:\eels\dev\st2\st2\index.pug", line 6, in render_body
body
File "z:\eels\dev\st2\env\lib\site-packages\markupsafe\_native.py", line 22, in escape
return Markup(text_type(s)
File "z:\eels\dev\st2\env\lib\site-packages\mako\runtime.py", line 226, in __str__
raise NameError("Undefined")
NameError: Undefined
似乎默认的mako渲染器被调用而不是哈巴狗。尝试使用PyJade以及.jade
扩展程序,但结果相同。
我做错了什么?
答案 0 :(得分:1)
问题出在pug / jade模板上,其中使用了未定义(未透露)的变量。