flask之Jinja2过滤器使用

局部函数 -- 只能在传入的template中使用,直接定义,传递

      def add_num(a,b):
        return int(a) + int(b)

    返回时:
        return render_template('..html','add_num':add_num)

    使用:
        {{add_num(1,2)}}

全局  -- 全局使用

    django 的 filter可以当做if条件

    需要 @app.template_global()装饰器   
         def func(a,b,c)  --->>  全局temlate使用 {{func(a,b,c)}}

      和 @app.template_filter()装饰器
         def func(a,b,c)  --->>  全局temlate使用 {{a|filter(b,c)}}  # 需要管道符

版权声明:除特别注明外,本站所有文章均为王晨曦个人站点原创

转载请注明:出处来自王晨曦个人站点 » flask之Jinja2过滤器使用

点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注

  1. Lance 说道:

    I am really glad to glance at this website posts which carries tons of useful data, thanks for providing such data.

  2. Zenaida 说道:

    Thanks very interesting blog!

  3. The legal landscape concerning hydroxychloroquine sulfate tablet 200 mg price is constantly evolving, with intellectual property rights and patent expirations influencing its availability and pricing. Legal experts and policymakers are engaged in a delicate balancing act, striving to protect innovation while ensuring that essential medications remain accessible to those in need.

  4. this hyperlink 说道:

    Wonderful blog! I found it while surfing around on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I've been trying for a while but I never seem to get there! Thank you