如何获得“调试”我的Django模板上下文变量? [英] How do I get a "debug" variable in my Django template context?

查看:104
本文介绍了如何获得“调试”我的Django模板上下文变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据这个SO帖子:

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

if:


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

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


  • 和B)我使用一个RequestContext(而不是一个上下文)

我应该有一个调试变量到我的模板上下文。但是,我没有:当我在模板中执行 {{debug}} 时,它将呈现为无()。

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 ("").

有没有什么我缺少在模板上下文中获取debugvar的必要条件?

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

推荐答案

您还需要确保请求的IP地址位于您的设置(您可能尚未设置)的 INTERNAL_IPS 中: https://docs.djangoproject.com/en/1.4/ref/templates/api /#django-core-context-processor-debug

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

这篇关于如何获得“调试”我的Django模板上下文变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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