47

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

Community
  • 1
  • 1
andilabs
  • 22,159
  • 14
  • 114
  • 151
  • This is essentially the same question as http://stackoverflow.com/questions/1271631/how-to-check-the-template-debug-flag-in-a-django-template/1271914, and the answer should probably be in that thread. (The answer to this question is also essentially the same as the accepted answer in the other thread.) – mipadi Sep 24 '15 at 15:18

1 Answers1

81

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.

Udi
  • 29,222
  • 9
  • 96
  • 129
andilabs
  • 22,159
  • 14
  • 114
  • 151