Jinja 2 safe keyword

前端 未结 3 1221
故里飘歌
故里飘歌 2021-02-04 01:28

I have a little problem understanding what an expression like {{ something.render() | safe }} does .

From what I have seen, without the safe ke

3条回答
  •  时光取名叫无心
    2021-02-04 02:12

    Normally text is HTML-escaped (so would be written out as <b>, which would render as ).

    When you put |safe after something, you're telling the template engine that you have already escaped the text yourself, i.e. "it's safe to render this directly". So it will not do that encoding for you.

    For more information: http://jinja.pocoo.org/docs/templates/#html-escaping

提交回复
热议问题