Home > Enterprise >  show text as it is entered in input box
show text as it is entered in input box

Time:05-17

I have created a Q&A website in Django I want to print text in the same format as it entered

This is the text
This is on a new line

It should print in this format as it is entered but it prints like this

This is the text This is on a new line

my forum.html code

 <div >
                      <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  style="color:blue; font-size: 13px;">Show more </button>  </a>
 {% endif %}
</div>

please help me to do this

CodePudding user response:

The documentation for truncatewords mentions:

Newlines within the string will be removed.

Hence you need to use the linebreaks filter first and then instead of truncatewords you should use truncatewords_html:

{{ post.post_content|linebreaks|truncatewords_html:10 }}
  • Related