在烧瓶应用程序上下文中,我尝试使用jinja2自定义过滤器处理一些文本:
例如:
<td>{{ data.get('value') | convert(data.get('unit'), 'psi') }}</td>
效果很好,convert()
是我的自定义过滤器。
但是,当我尝试传递用户设置时(来自烧瓶应用:current_user.pref_display_unit
):
<td>{{ data.get('value') | convert(data.get('unit'), {{ current_user.pref_display_unit }}) }}</td>
失败了:
File "N:\05-dev\flask_dev\carnac\carnac\templates\honeycomb\index.html", line 42, in template
<td>{{ data.get('long beam_L') | convert(data.get('unit'), {{ current_user.pref_display_thousandsep }}) }}</td>
TemplateSyntaxError: expected token ':', got '}'
那么,如何将这样的varable传递给过滤器?
答案 0 :(得分:2)
对不起噪音:这个很容易。只需传递变量本身不带括号:
<td>{{ data.get('value') | convert(data.get('unit'), current_user.pref_display_unit) }}</td>