显示在输入框中输入的文本

show text as it is entered in input box

我在 Django 中创建了一个问答网站我想以输入的格式打印文本

This is the text
This is on a new line

它应该按照输入的格式打印,但它打印成这样

This is the text This is on a new line

我的forum.html代码

 <div class="card-body cardbody">
                      <p>{{post.post_content|truncatewords:"10"|linebreaks}}</p>{% if post.post_content|length|get_digit:"-1" > 50 %} 
       <a href="/discussion/{{post.id}}" data-abc="true"><button class="btn btn-light" style="color:blue; font-size: 13px;">Show more </button>  </a>
 {% endif %}
</div>

请帮我做这个

truncatewords 的文档提到:

Newlines within the string will be removed.

因此您需要先使用 linebreaks 过滤器,然后您应该使用 truncatewords_html:

而不是 truncatewords
{{ post.post_content|linebreaks|truncatewords_html:10 }}