在Django模板中显示未定义的变量错误? [英] Show undefined variable errors in Django templates?

查看:147
本文介绍了在Django模板中显示未定义的变量错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何要求Django在呈现模板时遇到未定义的变量错误时告诉我?

How can I ask Django to tell me when it encounters, for example, an undefined variable error while it's rendering templates?

我尝试了明显的 DEBUG = True TEMPLATE_DEBUG = True ,但它们无济于事。

I've tried the obvious DEBUG = True and TEMPLATE_DEBUG = True, but they don't help.

推荐答案

根据django文档,
未定义变量默认情况下被视为(空字符串)。在如果要重新组合时,它是
如果要标识未定义的变量,请在设置中更改TEMPLATE_STRING_IF_INVALID。
‘%s’使无效变量作为变量名呈现,这样,您可以轻松识别。
how-invalid-variables-are-已处理

According to the django documentation, undefined variables are treated as ''(empty string) by default. While in if for regroup, it's None. If you are going to identify the variable undefined, change TEMPLATE_STRING_IF_INVALID in settings. '%s' makes the invalid variable to be rendered as its variable name, in this way, u can identify easily. how-invalid-variables-are-handled

这篇关于在Django模板中显示未定义的变量错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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