在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