How to output text ...
 
Notifications
Clear all

How to output text from database with line breaks in a django template  

  RSS

Anamika
(@anamika)
Noble Member
Joined: 4 months ago
Posts: 1179
20/03/2021 9:58 am  

I have text saved in a database record that looks like this.

This is the text

This is on a new line with a space in between

When I output it on the Django template, it comes out like this

This is the text This is on a new line with a space in between

How can I output the text on my django template to reflect the way it appears in the database?


Quote
Abhijith
(@abhijith)
Noble Member
Joined: 4 months ago
Posts: 1161
20/03/2021 10:00 am  

Use linebreaks or linebreaksbr filter:

{{ text|linebreaks }}

Or surround the text with <pre>...</pre>.

<pre>{{ text }}</pre>

Hope this helps!

Thank You!!


ReplyQuote
Share: