Opened 8 years ago

Closed 7 years ago

#7931 closed (invalid)

Debug mode causes template includes to be parsed regardless of if tags

Reported by: hmurray@… Owned by: nobody
Component: Template system Version: master
Severity: Keywords: template debug include tags
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


When running django in debug mode, django appears to parse all template include tags, even if an include tag will never be included. For example:

{% if condition %}

{% include "template_that_will_crash_if_condition_is_false.html" %}

{% endif %}

In DEBUG mode, errors (i.e. loading template tags) in the included template will be thrown, even if the template is never actually included because of the if condition. If debug is not enabled, then no errors are thrown.

The result should be the same whether in debug mode or not.

Change History (5)

comment:1 Changed 8 years ago by Johannes Dollinger

#7815 would fix this.

Here's a workaround (since #7815 might be wontfix):

{% if condition %}
    {% with "template_that_will_crash_if_condition_is_false.html" as tpl_name %}
        {% include tpl_name %}
    {% endwith %}
{% endif %} 

comment:2 Changed 8 years ago by Eric Holscher

Triage Stage: UnreviewedDesign decision needed

comment:3 Changed 8 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

comment:4 Changed 7 years ago by anonymous

see also: #12064

comment:5 Changed 7 years ago by Chris Beaven

Resolution: invalid
Status: newclosed

The change in behavior is reliant on settings.TEMPLATE_DEBUG (which usually is set to the same as DEBUG).

There is no bug here: the template includes are parsed in both situations, the error is just swallowed silently if not in debug mode.

As to whether the templates *should* always be parsed, we've got #12064 to talk about that now.

Note: See TracTickets for help on using tickets.
Back to Top