Allowing
tags with Google App Engine and Jinja2

后端 未结 8 1720
粉色の甜心
粉色の甜心 2021-01-04 22:11

In my web app, the user can make blog posts. When I display the blog post, newlines aren\'t shown because I didn\'t replace the new lines with
tags.

8条回答
  •  时光取名叫无心
    2021-01-04 22:41

    Note that i have autoescape on by default, so I don't check it in this function, but this is what I'm using

    def nl2br(value): 
      split = value.split('\n')
      return jinja2.Markup('
    ').join(split)

    then of course,

    jinja_env.filters['nl2br'] = nl2br
    

提交回复
热议问题