How to check the TEMPLATE_DEBUG flag in a django template?

If modifying INTERNAL_IPS is not possible/suitable, you can do this with a context processor:

in myapp/context_processors.py:

from django.conf import settings

def debug(context):
  return {'DEBUG': settings.DEBUG}

in settings.py:

TEMPLATE_CONTEXT_PROCESSORS = (
    ...
    'myapp.context_processors.debug',
)

Then in my templates, simply:

 {% if DEBUG %} .header { background:#f00; } {% endif %}

Assuming you haven't set TEMPLATE_CONTEXT_PROCESSORS to some other value in settings.py, Django will automatically load the debug context preprocessor (as noted here). This means that you will have access to a variable called debug in your templates if settings.DEBUG is true and your local machine's IP address (which can simply be 127.0.0.1) is set in the variable settings.INTERNAL_IPS (which is described here). settings.INTERNAL_IPS is a tuple or list of IP addresses that Django should recognize as "internal".