Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 315
Dap Avatar asked Mar 20 '14 15:03

Dap


1 Answers

Use linebreaks or linebreaksbr filter:

{{ text|linebreaks }}

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

<pre>{{ text }}</pre>
like image 79
falsetru Avatar answered Oct 05 '22 23:10

falsetru