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

0 votes

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?

Jun 24 in Python by kartik
• 30,930 points
468 views

1 answer to this question.

+1 vote

Hello @kartik,

Use linebreaks or linebreaksbr filter:

{{ text|linebreaks }}

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

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

Hope this helps!

Thank You!!

answered Jun 24 by Niroj
• 67,020 points
Thank you very much

Related Questions In Python

0 votes
0 answers
0 votes
1 answer
0 votes
1 answer

How to zip with a list output in Python instead of a tuple output?

Good question - Considering that you are ...READ MORE

answered Feb 7, 2019 in Python by Nymeria
• 3,520 points
261 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

ProgrammingError: not all arguments converted during string formatting

Sorted!!!! just found the solution, 1 - apparently ...READ MORE

answered Sep 10, 2018 in Python by Priyaj
• 57,700 points
9,930 views
0 votes
1 answer

Create a database table using python

Hey @Kim, try something like this: import MySQLdb # ...READ MORE

answered Jul 22, 2019 in Python by Barbara
136 views
0 votes
1 answer

ModuleNotFoundError: No module named 'mysql'

Hi@akhtar, You need to install mysql-connector to connect ...READ MORE

answered Jul 15 in Python by MD
• 66,340 points
2,071 views
0 votes
1 answer

How to clear a database from the CLI with manage.py in Django?

Hello @kartik, To drop the database and run syncdb again. ...READ MORE

answered Aug 7 in Python by Niroj
• 67,020 points
131 views
0 votes
1 answer

How to look up a dictionary value with a variable in Django template?

Hii @kartik, Write a custom template filter: from django.template.defaulttags ...READ MORE

answered Aug 3 in Python by Niroj
• 67,020 points
368 views