【问题标题】:breakpoints in flask jinja templates烧瓶神社模板中的断点
【发布时间】:2016-12-15 23:41:10
【问题描述】:

有没有办法在从 flask 渲染的 jinja 模板中放置断点?也许可以让您在模板的各个点检查模板可用的变量?我看到一个博客说你可以在 django https://opensourcehacker.com/2013/05/16/putting-breakpoints-to-html-templates-in-python/ 中做到这一点,希望使用烧瓶有类似的东西。

【问题讨论】:

    标签: python debugging flask jinja2


    【解决方案1】:

    Flask 有 app_context_processor 使变量在模板上可用:

    上下文处理器在模板渲染之前运行,并且能够将新值注入到模板上下文中。

    class Letters():
        A = 1
        B = 2
    
    @app.context_processor
    def share_context():
        return dict(Letters=Letters)
    
    Now you can access this class
    
    # index.html
    {{ Letters.A }}
    {% if Letters.B != 1 %}
    ...
    {% endif %}
    

    flask context processors

    【讨论】:

      猜你喜欢
      • 2020-04-27
      • 2016-04-20
      • 1970-01-01
      • 1970-01-01
      • 2021-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-10
      相关资源
      最近更新 更多