使django模板严格 [英] Make django templates strict
问题描述
在django模板中,如果 var
未定义,则调用 {{var}}
将静默失败。这使得模板难以调试。有没有一个设置我可以切换,所以django会抛出一个异常在这种情况下?
In a django template, a call to {{ var }}
will silently fail if var
is undefined. That makes templates hard to debug. Is there a setting I can switch so django will throw an exception in this case?
我在网上找到的解决方案的唯一提示是 http://groups.google.com/group/google-appengine/browse_thread/thread/86a5b12ff868038d ,这听起来
The only hint at a solution I've found online is http://groups.google.com/group/google-appengine/browse_thread/thread/86a5b12ff868038d and that sounds awfully hacky.
推荐答案
设置 TEMPLATE_STRING_IF_INVALID ='DEBUG WARNING:未找到未定义的模板变量[%s] '
在您的 settings.py
中。
阅读以下文档:
http://docs.djangoproject.com / en / dev / ref / settings /#template-string-if-invalid
http://docs.djangoproject.com/en/dev/ref/templates/api/#invalid-template-variables
这篇关于使django模板严格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!