class Filter(object):

    def __init__(self, filter_name=None):
        self.filter_name = filter_name

def __call__(self, function):
    my_jinja_env.filters[self.filter_name or function.__name__] = function
return function

@Filter()
def i_love_you(name):
    """ say I love you to the name you entered. 
    usage: {{ "John" | i_love_you }} => "I Love You, John!\""""
return 'I Love You, %s!' % name
Лямбда-выражения Python в Jinja2