'show text as it is entered in input box
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 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>
please help me to do this
Solution 1:[1]
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 }}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Abdul Aziz Barkat |
