I have text saved in a mysql 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
Do I have to pre format this in the views or is there a django, templating syntax to achieve this? How can I output the text to reflect the way it appears in the database?
Use linebreaks
or linebreaksbr
filter:
{{ text|linebreaks }}
Or surround the text with <pre>...</pre>
.
<pre>{{ text }}</pre>
Try to use <br/>
<br/>
is an HTML code. Don't forget you are working with HTML using Django. Keeping this in mind will solve a lot of beginners trouble.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.