包含的 django 模板中的错误未呈现 [英] Error in included django template is not rendered

查看:44
本文介绍了包含的 django 模板中的错误未呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 imgix 插件的简单模板,如下所示:

I have this simple template that uses the imgix plugin like so:

// template_b.html
{% get_imgix project.picture %} 

此行导致错误,应替换为

This line causes an error and should be replaced by

{% get_imgix project.picture.url %}

这段代码位于包含的模板中:

This piece of code is inside a template that is included:

// template_a.html
{% include "template_b.html" %}

似乎当模板标记失败时,在第一种情况下(引发 AttributeError),模板会简单被忽略.如果 DEBUG 设置为 False,则不会引发错误.

It seems that when the template tags fails, in the first case (an AttributeError is raised), the template is simply ignored. No error is raised if the DEBUG setting is False.

虽然这对于防止任何面向用户的错误确实很有用,但没有任何反馈仍然令人担忧.

While this is certainly useful to prevent any user-facing errors, it's still concerning to not have any kind of feedback.

您知道我可以在哪里找到与此行为相关的更多信息吗?是否还有其他方法可以通知失败?

Do you know where I can find more information related to this behavior and if there are ways to still be informed of the failure?

推荐答案

您并不是唯一一个被这种行为所困扰的人.请参阅 django-developers 邮件列表上的此讨论.

You're not the only person to have been caught out from this behaviour. See this discussion on the django-developers mailing list.

静音行为已在 Django 1.11 中弃用.在 Django 2.1 中,将引发异常.在 Django 1.11 和 2.0 中,如果包含标记引发异常,您会收到弃用警告,但异常已被静音.

The silencing behaviour has been deprecated in Django 1.11. In Django 2.1 the exception will be raised. In Django 1.11 and 2.0 you get a deprecation warning if the include tag raises and exception, but the exception is silenced.

我对 Django 的早期版本没有任何好的建议.如果它对您很重要,您可以创建自己的 include 标记.

I don't have any good suggestions for earlier versions of Django. You could create your own include tag if it's really important to you.

这篇关于包含的 django 模板中的错误未呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆