newline in models.TextField() not rendered in template
linebreaks
Replaces line breaks in plain text with appropriate HTML; a single newline becomes an HTML line break (
<br />
) and a new line followed by a blank line becomes a paragraph break (</p>
).For example:
{{ value|linebreaks }}
Just a note, I was having a similar problem with newlines not showing up and I realized that when a TextField is declared as readonly, the text is wrapped with HTML paragraph tags:
<p> text </p>
as opposed to pre tags:
<pre> text </pre>
Pre tags preserve new line spaces, so if you do NOT make the field readonly, you will see the linespaces.