更好的错误报告 mako

发布于 2024-09-02 11:41:00 字数 39 浏览 0 评论 0原文

有没有办法将包含错误的模板字符串添加到 mako 的错误跟踪中?

Is there a way to add tempate string which contains error to mako`s error trace?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空城缀染半城烟沙 2024-09-09 11:41:00

我认为你不太可能找到这样的东西。与所有其他快速 Python 模板引擎一样,Mako 通过将模板编译为 Python 代码然后执行它来实现其速度。异常会将执行转移到模板代码之外,因此当引发异常时,该模板将无法显示它(或执行任何其他操作)。

作为替代方案,我建议将模板渲染代码放入 try 块中,并使用专门用于该目的的单独模板来渲染任何捕获的异常。

I don't think you're likely to find such a thing. Like all the other fast python template engines, Mako achieves its speed by compiling your template into python code and then executing it. An exception will divert execution out of your template's code, so by the time one is raised, that template will have no way of displaying it (or doing anything else for that matter).

As an alternative, I suggest putting your template rendering code inside a try block, and rendering any caught exceptions with a separate template used specifically for that purpose.

梦里寻她 2024-09-09 11:41:00

我正在寻找另一个错误并发现了这个。我想如果您仍然需要这个,那就太好了,您可以通过设置mako.strict_undefined = True来实现它。我使用的是 mako-0.6.2,所以在 2010 年的版本中可能无法实现。

I was looking for another error I have and found this. I though it would be nice if you still ever need this, you can achieve it by setting mako.strict_undefined = True. I am using mako-0.6.2 so it may not been possible in the version back in 2010.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文