how to check DEBUG true/false in django template - exactly in layout.html [duplicate]

笑着哭i 提交于 2019-12-03 10:32:13

问题


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


回答1:


In newer versions of Django it is possible just by specifying INTERNAL_IPS in settings.

For example:

INTERNAL_IPS = (
    '127.0.0.1',
    '192.168.1.23',
)

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.



来源:https://stackoverflow.com/questions/25783459/how-to-check-debug-true-false-in-django-template-exactly-in-layout-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!