@staticmethod
def _escape_attribute_quotes(v, attr_wrapper):
    """
        Escapes quotes with a backslash, except those inside a Django tag
        """
    escaped = []
    inside_tag = False
    for i, _ in enumerate(v):
        if v[i:i + 2] == '{%':
            inside_tag = True
        elif v[i:i + 2] == '%}':
            inside_tag = False
        if v[i] == attr_wrapper and not inside_tag:
            escaped.append('\\')
        escaped.append(v[i])
    return ''.join(escaped)
