On Fri, Jan 13, 2012 at 9:30 PM, Ioan Alexandru Cucu
<alexandruioan.c...@gmail.com> wrote:
> Hi guys,
>
> Using django 1.1.1
> Example template snippet template snippet:
>
> {{ foo.bar }}
>
> If 'bar' raises an AttributeError, the exception is silenced and an
> empty string is displayed.
> I tried setting DEBUG, TEMPLATE_DEBUG, and DEBUG_PROPAGATE_EXCEPTIONS
> to True, but nothing changes.
>
> Digging through django's source code, it looks like silencing the
> error is a normal django behavior.
>
> Should this be considered a bug in django? I mean, even though the bug
> is in 'my' code and that code should be unit tested decoupled from the
> template rendering part, it would be nice to have a setting for
> showing the same django error page as if the exception would have been
> raised in the view code.

It's not a bug, it's a specific design decision.

The underlying philosophy is that the worst thing a web app can do is
show an error to the user in the middle of 'normal' content (think of
the PHP apps that dump MySQL stack traces in the middle of pages when
they fail).

As a side effect -- once you know that non-existent attributes won't
raise an error, you can actually start to rely on this fact in your
template design. Django's admin templates exploit this in a couple of
places.

If you need help finding places in your template where missing
attributes are being swallowed, you can use the
TEMPLATE_STRING_IF_INVALID setting -- this sets the value that is used
when a template variable can't be found, so you can force "NOT HERE"
to be rendered instead of an empty string. This isn't something you
want to keep turned on in production, and if it is enabled, Django's
admin will have some interesting rendering problems, but it can be a
helpful debugging tool.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to