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

后端 未结 3 1412
误落风尘
误落风尘 2021-02-18 22:45

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 o

相关标签:
3条回答
  • 2021-02-18 23:23

    I linebreaks uses <p> tag to convert new line, this will probally not preserve the empty line or you will just not see it due to css styling. You can try instead linkebrksbr that will use <br/> for new lines.

    Hope this helps

    0 讨论(0)
  • 2021-02-18 23:23

    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.

    0 讨论(0)
  • 2021-02-18 23:38

    Use linebreaks or linebreaksbr filter:

    {{ text|linebreaks }}
    

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

    <pre>{{ text }}</pre>
    
    0 讨论(0)
提交回复
热议问题