Search code examples
pythonpyramidpyjade

PyPugJs with Pyramid - Basic


I am trying to use PyPugJs with Pyramid. Inside my __init.py, I have this

config.include('pypugjs.ext.pyramid')

Inside 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 {}

And I get this error when trying to go to the index route

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

It seems that the default mako renderer is being called rather than pug. Tried using PyJade as well with .jade extension, but with the same result. What am I doing wrong ?


Solution

  • The issue was with the pug/jade template, where an undefined(unpassed) variable was being used.