flask过滤器filter是不是只作用在字符串上

来源:3-1 模板语法之模板标签(上)

麦兜搞_IT

2023-04-17 12:06:27

# 在app.py中
@app.route('/index')
def use_filter():
    str = 'hellopython'
    lists = [5,6,7,3,4,2,1]
    return render_template('index.html', lists=lists, str=str)

# 在模版中使用filter过滤器报错
{% filter sort %}
   {{ lists }}
{% endfilter %}

# 在模版中使用管道式过滤器则正常显示
{{ lists|sort }}

# 使用filter过滤器报错

https://img.mukewang.com/climg/643cc5b00918b95f10720158.jpg

写回答

1回答

好帮手慕小猿

2023-04-17

同学,你好!是没有{%filter  sort%} 这种写法,是字符串类型的数据也报错

https://img.mukewang.com/climg/643cda70096f3bbb08250602.jpg

https://img.mukewang.com/climg/643cda5709289de613740677.jpg

祝学习愉快~

0

0 学习 · 4469 问题

查看课程