Raise Exception on invalid template variable

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# settings.py
class InvalidVarException(object):
    def __mod__(self, missing):
        try:
            missing_str=unicode(missing)
        except:
            missing_str='Failed to create string representation'
        raise Exception('Unknown template variable %r %s' % (missing, missing_str))
    def __contains__(self, search):
        if search=='%s':
            return True
        return False

TEMPLATE_DEBUG=True
TEMPLATE_STRING_IF_INVALID = InvalidVarException()

More like this

  1. urlquote() and urlencode() in one method by guettli 4 years, 7 months ago
  2. Non-pickling locmem (in-process memory) cache backend by akaihola 2 years, 3 months ago
  3. Complex Form Preview by smagala 4 years, 2 months ago
  4. Template filter implementing the Trac wiki markup language by simon 4 years, 9 months ago
  5. Pass db.Field to newforms.Widget by guettli 5 years, 11 months ago

Comments

guettli (on September 30, 2008):

Related ticket: #6766

#

(Forgotten your password?)