Opened 16 years ago

Closed 15 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: dev
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: no UI/UX: no

Description

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 by Johannes Dollinger, 16 years ago

#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 by Eric Holscher, 16 years ago

Triage Stage: UnreviewedDesign decision needed

comment:3 by (none), 15 years ago

milestone: post-1.0

Milestone post-1.0 deleted

comment:4 by anonymous, 15 years ago

see also: #12064

comment:5 by Chris Beaven, 15 years ago

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