This recipe raises an exception if there is an invalid variable in the template.
See #6766
Note: I don't need this snippet any more, since I don't use the template language any more. For my projects using only python is better (complex logic, simple layout).
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
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
Please login first before commenting.