烧瓶Jinja2自定义模板过滤器崩溃

时间:2015-10-05 17:46:40

标签: python flask jinja2

我在django-app中成功使用了以下过滤器(只是更改了语法,因此它适用于烧瓶):

@blueprint.app_template_filter('process_trans_for_html')
def process_trans_for_html(string):
    def replace_xn(match):
        match = match.group()
        return   x_HK_to_UNI(match[:1]).upper()+x_HK_to_UNI(match[1:3]).lower()
    def replace_xh(match):
        match = match.group()
        return x_HK_to_UNI(match)
    string = re.sub("([a-zA-Z])+_xn", replace_xn, string)
    string = re.sub("([a-zA-Z])+_xh", replace_xh, string)
    return string

它一直在崩溃。但是,如果我使用相同的过滤器并删除replace_xh定义并调用它,它的工作没有任何问题:

@blueprint.app_template_filter('process_trans_for_html')
def process_trans_for_html(string):
    def replace_xn(match):
        match = match.group()
        return   x_HK_to_UNI(match[:1]).upper()+x_HK_to_UNI(match[1:3]).lower()
    string = re.sub("([a-zA-Z])+_xn", replace_xn, string)
    return string

这段代码没有问题。有什么建议吗?对我来说似乎很随机也很奇怪。

0 个答案:

没有答案
相关问题