gar*_*ois 10 django django-templates django-errors
在django模板中,{{ var }}如果var未定义,则调用将静默失败.这使模板难以调试.有没有我可以切换的设置,所以django会在这种情况下抛出异常?
我在网上找到的解决方案的唯一提示是http://groups.google.com/group/google-appengine/browse_thread/thread/86a5b12ff868038d,听起来非常黑客.
的Django <= 1.9
设置TEMPLATE_STRING_IF_INVALID = 'DEBUG WARNING: undefined template variable [%s] not found'您的settings.py。
参见文档:https :
//docs.djangoproject.com/zh-CN/1.9/ref/settings/#template-string-if-invalid
的Django> = 1.10
在中设置string_if_invalid = 'DEBUG WARNING: undefined template variable [%s] not found'模板选项settings.py。
参见文档:https : //docs.djangoproject.com/en/2.0/topics/templates/#module-django.template.backends.django
另请阅读:http : //docs.djangoproject.com/en/dev/ref/templates/api/#invalid-template-variables