Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Django's TEMPLATE_DEBUG setting for?

I have been trying to find information about this setting but there isn't much. Can someone explain me what is this setting about? Should I turn it off in production?... Just want to learn about it, maybe I'm missing something important in django.

(I use django 1.6)

like image 331
Alejandro Veintimilla Avatar asked Aug 12 '14 22:08

Alejandro Veintimilla


1 Answers

This setting helps with debugging errors/exceptions raised while rendering the templates.

If it is set to True and DEBUG is True, Django would show you usual "fancy" error page with a traceback, request details and other important information, and highlight at which line the error happened.

If it is set to False and DEBUG is True and there was an error while rendering the template, you would still see the Django's error page, but it would miss the block containing template code where the error occurred. So it would be more difficult to debug.

It is a good practice to make sure the value of TEMPLATE_DEBUG is the same as DEBUG (though if DEBUG is False, the error page would not be shown):

DEBUG = TEMPLATE_DEBUG = True   # development
DEBUG = TEMPLATE_DEBUG = False  # production

Documentation reference.


Example.

Imagine we have an error in the template, forgot to provide the date format in the now template tag:

<div>
    <span class="date">
        {% now %}
    </span>
</div>

DEBUG is set to True.

In case of TEMPLATE_DEBUG=True the Django's fancy error page would contain the following block:

enter image description here

If TEMPLATE_DEBUG=False, this block would not be visible.

Hope that helps.

like image 94
alecxe Avatar answered Oct 28 '22 03:10

alecxe