from django.template import Variable, VariableDoesNotExist QUOTED_STRING = re.compile(r'^["\'](?P.+)["\']$') def handle_var(self, value, context): stringval = QUOTED_STRING.search(value) if stringval: return stringval.group('noquotes') else: try: return Variable(value).resolve(context) except VariableDoesNotExist: return value