1

So I'm trying to make a custom-filter in Flask, I am not sure if I can use custom filters with blueprints, so I just put it in my app config, because I can't use @app decorator in other files.

def configure_jinja2(app):
    urlize = app.jinja_env.filters['urlize']
    truncate = app.jinja_env.filters['truncate']
    @app.template_filter('myfilter')
    def myfilter(s, trim=False, trunc=255):
        s = urlize(s)
        if trim:
          s = truncate(s, trunc)
        return s

So I'm trying to combine 2 built-in jinja2 filters, to create a new custom filter that will also do other stuff.

This gives an error: TypeError: do_urlize() takes at least 2 arguments (1 given)

What do I put in for eval_context?

https://github.com/mitsuhiko/jinja2/blob/master/jinja2/filters.py

4

1 回答 1

3

jinja2.filters.do_urlize只是 jinja2.utils.urlize 的一个薄包装,它不需要 eval_context 大多数其他采用评估上下文的内置过滤器似乎也是如此。

于 2013-04-27T16:36:26.987 回答