template = '{% block body %} This is x.foo: {{ x.foo }} {% endblock %}'
expr = '\\{\\{.*x.*\\}\\}'
result = re.search(expr, template)
try:
    print(result.group(0))
except IndexError:
    print('Variable not used')
How to check if given variable exist in jinja2 template?