This rule is the correct one, and I'm very much against changing it.
> [...] but some of Django's own template tags (e.g. `widthratio`) don't adhere to
> this policy.
These are bugs, and should be fixed.
> I'd like to see a move towards consistent exception handling in
> templates for template tags and filters. I'd like to see no exceptions
> silenced by default, but provide a way for template authors to
> conditionally silence exceptions in fragments of their templates.
> Perhaps with a block tag.
I'm against this, for a whole host of reasons — the crux of which
comes down to the philosophy that templates are *not* a programming
language, and introducing a try/except concept into them is about
seven steps too far.
The point of the template language is to give front end designers and
developers the space to explore without the persnicketiness a
so-called "real" programming language introduces. What you're asking
for here is to fundamentally change the philosophy of the template
language. If you disagree that fundamentally with the ideas behind the
template language I really think you'll be better off finding another
one than trying to swim upstream.
> Should built-in template tags follow the advice given in the docs, and
> never raise `TemplateSyntaxError` in their `render()` function?
Yes; the two instances you mentioned are bugs and should be fixed.
Jacob
I agree with what you propose but AFAIK it's not easy to solve without
doing frame analysis (I'd say that feature is not worth doing such
hacks). That's because of the way `hasattr` is implemented:
def hasattr(obj, attr):
try:
getattr(obj, attr)
return True
except AttributeError:
return False
This code directly mirrors the code found in CPython and implies that
/hasattr "executes" properties/.
So there's no way to figure out whether an attribute exists without
executing the code of properties.
Jonas
--
Django + MongoDB: http://django-mongodb.org
Secondly, there is the inconsistent behaviour between production and
development environments related to the `TEMPLATE_DEBUG` setting. I
think that if an exception is intentionally silenced in production, it
should also be intentionally silenced with `TEMPLATE_DEBUG = True`, to
allow for consistent behaviour during development.