I’ve found that trying to access an undefined variable within a Mako template raises a NameError, and quite logically so. In some applications, however, it’s desirable to fail more gracefully, perhaps substituting the empty string on such errors (AttributeError is another candidate). This is the default behavior in the Django template language. Is there a way to get this behavior in Mako?
I’ve found that trying to access an undefined variable within a Mako template raises
Share
Well, turns out that a little more googling makes it plain:
Now undefined variables will produce the empty string.
Reading the source for the original value of UNDEFINED is enlightening:
And there we go. Thanks, Google.