2👍
✅
Try paranoid django templates solution:
class ParanoidContextProxy(object):
"""
This is a poor-man's proxy for a context instance.
Make sure template rendering stops immediately on a KeyError.
"""
def __init__(self, context):
self.context = context
self.seen_keys = set()
def __getitem__(self, key):
self.seen_keys.add(key)
try:
return self.context[key]
except KeyError:
raise ParanoidKeyError('ParanoidKeyError: %r' % (key,))
def __getattr__(self, name):
return getattr(self.context, name)
def __setitem__(self, key, value):
self.context[key] = value
def __delitem__(self, key):
del self.context[key]
Source:stackexchange.com