gpt4 book ai didi

python - PyPugJs 与 Pyramid - 基础

转载 作者:太空宇宙 更新时间:2023-11-03 16:16:50 25 4
gpt4 key购买 nike

我正在尝试使用PyPugJs与 Pyramid 。在我的 __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 渲染器而不是 pug。尝试使用 PyJade以及 .jade 扩展名,但结果相同。我做错了什么?

最佳答案

问题出在 pug/jade 模板上,其中使用了未定义(未传递)的变量。

关于python - PyPugJs 与 Pyramid - 基础,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38878714/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com