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, 2020 in Python by kartik
• 37,510 points
12,726 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, 2020 by Niroj
• 82,880 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,560 points
1,402 views
0 votes
1 answer

I want to download a file from the website by web scraping. Can anyone explain how to do this in jupyter lab (python) with an example?

Hey, Web scraping is a technique to automatically ...READ MORE

answered Apr 7, 2020 in Python by Gitika
• 65,910 points
2,101 views
0 votes
1 answer

Error:Python3.4 can't install mysql-python

Hello @kartik, You can resolved this by the ...READ MORE

answered Jun 24, 2020 in Python by Niroj
• 82,880 points
1,823 views
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
• 58,090 points
19,661 views
0 votes
1 answer

Create a database table using python

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

answered Jul 23, 2019 in Python by Barbara
1,082 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, 2020 in Python by MD
• 95,440 points
49,340 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, 2020 in Python by Niroj
• 82,880 points
2,437 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, 2020 in Python by Niroj
• 82,880 points
10,096 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP