为什么我的Jinja追溯毫无意义?

时间:2012-04-03 18:10:57

标签: google-app-engine jinja2

我不知道为什么,但最近我从Jinja模板渲染得到的回溯 错误或多或少完全没有意义。

Traceback (most recent call last):
  File "/Users/me/my_project/app/distlib/tipfy/__init__.py", line 442, in wsgi_app
    response = self.handle_exception(request, e)
  File "/Users/me/my_project/app/distlib/tipfy/__init__.py", line 430, in wsgi_app
    rv = self.dispatch(request)
  File "/Users/me/my_project/app/distlib/tipfy/__init__.py", line 559, in dispatch
    return handler(self, request)(method, **request.rule_args)
  File "/Users/me/my_project/app/distlib/tipfy/__init__.py", line 165, in __call__
    response = method(*args, **kwargs)
  File "/Users/me/my_project/app/my_package/admin/menus/editor.py", line 22, in get
    return self.edit_week(menu, year, week_num, week_nums)
  File "/Users/me/my_project/app/my_package/admin/menus/editor.py", line 44, in edit_week
    return self.respond(data, context=ctx, template="admin/menus/edit.html")
  File "/Users/me/my_project/app/my_package/lib/irender.py", line 182, in respond
    return render(self, fmt, opts)
  File "/Users/me/my_project/app/my_package/lib/irender.py", line 207, in __call__
    val = render_func(handler, **opts)
  File "/Users/me/my_project/app/my_package/lib/irender.py", line 220, in render_html
    return handler.render_template(self.template, ctx)
  File "/Users/me/my_project/app/my_package/handlers.py", line 42, in render_template
    return jinja2.get_template(template).render(accum)
  File "/Users/me/my_project/app/distlib/jinja2/environment.py", line 894, in render
    return self.environment.handle_exception(exc_info, True)
  File "/Users/me/my_project/app/templates/admin/menus/edit.html", line 3, in top-level template code
    {% import "admin/utils.html" as utils %}
TypeError: integer argument expected, got float

当然,我可以通过删除大部分内容来推断实际错误的位置 模板并查看错误何时开始,但这是一个愚蠢的发展 方法

如何让追溯再次有用?

顺便说一句,我在main.py中有以下咒语:

def whitelist_jinja2_debug_modules():
    from google.appengine.tools.dev_appserver import HardenedModulesHook
    HardenedModulesHook._WHITE_LIST_C_MODULES += ['_ctypes', 'gestalt']

if app.dev:
    whitelist_jinja2_debug_modules()

1 个答案:

答案 0 :(得分:0)

即使这个问题已经很老了,答案也很容易获得(而不是同时)。要在Jinja中获得适当的堆栈跟踪,您需要拥有很长时间才能在Google应用引擎中使用的ctypes。我不完全确定目前的状态,但这个问题有一些解决方案: Debug Jinja2 in Google App Engine