如何使用python和flask(html jinja)从mysql打印换行而不使用<pre>

时间:2017-08-13 13:37:02

标签: python html jinja2

Gooday to all. I have been googling about some solutions on how to do this. I would like to print newlines from my database to html (like php's nl2br) So, I have stumbled on a post that says use <pre></pre> but it encapsulates the paragraph on a table like container enter image description here

It would not be any problem on a desktop but on mobile, you are gonna have to scroll side to side to see the contents, is there any way to print out something like this? (just the newlines without the pesky container like thing )

enter image description here

if I just call it directly using

{{article.notes | safe }}

It does not print newline. It just goes on like

1.Thisisacontentblablabla2.foobarbarbarbar3.loremipsumilovetoeatnoodles4.test

here is the code on html

{% extends 'layout.html' %}

{% block body %}

  <center>
    <h1>{{article.topic_name | safe }}</h1>
    <input type="submit" value="Edit" class="btn btn-danger">
  </center>
  <div>
  <h2> Procedures: </h2>
  <pre>
  <p align="left"> {{article.explaination | safe }} </p>
  </pre>
  </div>

  <div>
  <h2> User Notes: </h2>
  <pre>
  <p align="left"> {{article.notes | safe }} </p>
  </pre>
  </div>

  <div>
  <h2> Commands: </h2>
  <pre>
  <p align="left"> {{article.commands | safe }} </p>
  </pre>
</div>


{% endblock %}

Thankyou So Much in advance :)

1 个答案:

答案 0 :(得分:0)

我找到了这个问题的解决方案,这引起了另一个问题,但另一个话题是另一天:)

{{something | safe}}

只需将其封装在safe标记中即可执行

我还没有找到关于Xss的解决方案。因为它执行

标签。它还执行恶意JavaScript标记。我会问这个新问题