Error in included django template is not rendered

霸气de小男生 提交于 2019-12-07 14:15:56

问题


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" %}

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?


回答1:


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

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.

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.



来源:https://stackoverflow.com/questions/43758492/error-in-included-django-template-is-not-rendered

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!