Allowing
tags with Google App Engine and Jinja2

后端 未结 8 1746
粉色の甜心
粉色の甜心 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:50

    I have another answer that I think is the best. Initially I was just displaying my variable post.content as-is, and the newlines weren't being preserved. None of the solutions here worked (well), and my pre solution was just a quick fix and had major issues. This is the real solution:

    {% for line in post.content.splitlines() %}
        {{line}}
    {% endfor %}

提交回复
热议问题