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

查看:27
本文介绍了在 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 = TrueTEMPLATE_DEBUG = True,但它们没有帮助.

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

推荐答案

根据 django 文档,默认情况下,未定义的变量被视为 ''(空字符串).而在 if for regroup 中,它是 None.如果您要确定未定义的变量,请在设置中更改 TEMPLATE_STRING_IF_INVALID.'%s' 将无效的变量渲染为它的变量名,这样你就很容易识别了.how-invalid-variables-are-handled

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天全站免登陆