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

andilabs picture andilabs · Sep 11, 2014 · Viewed 17.6k times · Source

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

Answer

andilabs picture andilabs · Sep 11, 2014

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.