Jinja2 correctly indent included block

前端 未结 3 1646
深忆病人
深忆病人 2021-02-02 07:35

I have two files:

base.html



    
       
       

        
3条回答
  •  一生所求
    2021-02-02 07:42

    Good question. I believe Jinja2 does not do this.

    The main question you need to ask yourself is why you want the HTML to be correctly indented, since browsers do not care. In a production application it is more efficient to go the other way and strip all the white space to make the page smaller.

    If you are interested in doing this during development then you can pass the HTML generated by render_template() through an indenter such as prettify() from BeautifulSoup. I do not recommend this for a production system, since your functions will take longer to run.

提交回复
热议问题