如何在django模板中检查DEBUG true / false - 完全在layout.html中 [英] how to check DEBUG true/false in django template - exactly in layout.html

查看:254
本文介绍了如何在django模板中检查DEBUG true / false - 完全在layout.html中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想区分 layout.html 中某些工具栏的外观,具体取决于DEBUG = True。



我知道这个 django.core.context_processors.debug 但它强制我使用 RequestContext 而不是请求我不太喜欢,btw如何使用RequestContext为 layout.html 扩展 base.html



一般来说,有一些比所提及的更好的方法,或使用自定义模板标签的人? p>

我目前在Django 1.7中

解决方案

在较新版本的Django中可以通过指定 INTERNAL_IPS 在设置中,例如:

  INTERNAL_IPS =(
'0.0.0.0',
'127.0 .0.1',

然后在模板中:

  {%if debug%} 



因为默认情况下负责的上下文处理器,以及如何检查django模板中的TEMPLATE_DEBUG标志?被不推荐使用。


I would like distinguish a look of some toolbar in layout.html depending if DEBUG = True or not.

I am aware of this answer using django.core.context_processors.debug but it forces me to use RequestContext instead of Request what I not really like, btw how can I use RequestContext for layout.html which extends base.html?

And generally is there some better way to that than mentioned one or the one using custom template tag?

I am currently on Django 1.7

解决方案

In newer versions of Django it is possible just by specifyng INTERNAL_IPS in settings e.g.:

INTERNAL_IPS = (
    '0.0.0.0',
    '127.0.0.1',
)

and then in template just:

{% if debug %}

because context processors responsible for that by default, and the answers from How to check the TEMPLATE_DEBUG flag in a django template? are bit deprecated.

这篇关于如何在django模板中检查DEBUG true / false - 完全在layout.html中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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