in myapp/context_processors.py
:
from django.conf import settings
def debug(request):
return {'DEBUG': settings.DEBUG}
in settings.py
:
TEMPLATES = [
{
...
'OPTIONS': {
'context_processors': [
...
'myapp.context_processors.debug',
],
},
},
]
or, for versions < 1.9:
TEMPLATE_CONTEXT_PROCESSORS = (
...
'myapp.context_processors.debug',
)
Then in my templates, simply:
{% if DEBUG %} .header { background:#f00; } {% endif %}
{{ DEBUG }}