Minify HTML output from Flask application with Jinja2 templates

前端 未结 7 944
鱼传尺愫
鱼传尺愫 2021-02-02 11:24

Is there a Flask or Jinja2 configuration flag / extension to automatically minify the HTML output after rendering the template?

7条回答
  •  被撕碎了的回忆
    2021-02-02 11:38

    Use the decorator.

    from htmlmin.decorator import htmlmin
    
    @htmlmin
    def home():
    ...
    

    Or you can just use:

    re.sub(r'>\s+<', '><', '   ') # results ''
    

提交回复
热议问题