如何在Django模板上下文中获得“debug”变量?

时间:2022-04-21 06:52:56

According to this SO post:

根据这篇SO帖子:

How to check the TEMPLATE_DEBUG flag in a django template?

如何检查django模板中的TEMPLATE_DEBUG标志?

if:

如果:

  • A) my settings.py file has:
  • A)我的settings.py文件有:

TEMPLATE_CONTEXT_PROCESSORS = ['django.core.context_processors.debug',...

TEMPLATE_CONTEXT_PROCESSORS = ['django.core.context_processors.debug',...

  • and B) I use a RequestContext (as opposed to a Context)
  • 和B)我使用RequestContext(而不是Context)

I should have a "debug" variable to my template context. However, I don't: when I do {{debug}} in a template, it renders as nothing ("").

我的模板上下文应该有一个“debug”变量。但是,我没有:当我在模板中执行{{debug}}时,它会呈现为空(“”)。

Is there anything else I'm missing that is necessary to get a "debug" var in the template context?

还有什么我不知道在模板上下文中获得“debug”var所必需的吗?

1 个解决方案

#1


19  

You also need to ensure the request's IP address is in the INTERNAL_IPS in your settings (which you probably don't have set): https://docs.djangoproject.com/en/1.4/ref/templates/api/#django-core-context-processors-debug

您还需要确保请求的IP地址在您的设置中的INTERNAL_IPS中(您可能没有设置):https://docs.djangoproject.com/en/1.4/ref/templates/api/#django-核心上下文处理器调试

#1


19  

You also need to ensure the request's IP address is in the INTERNAL_IPS in your settings (which you probably don't have set): https://docs.djangoproject.com/en/1.4/ref/templates/api/#django-core-context-processors-debug

您还需要确保请求的IP地址在您的设置中的INTERNAL_IPS中(您可能没有设置):https://docs.djangoproject.com/en/1.4/ref/templates/api/#django-核心上下文处理器调试