如何在django模板中检查DEBUG true / false - 完全在layout.html中 [英] how to check DEBUG true/false in django template - exactly in layout.html
问题描述
我想区分 layout.html
中某些工具栏的外观,具体取决于DEBUG = True。
一般来说,有一些比所提及的更好的方法,或使用自定义模板标签的人? 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屋!