Paul Zet
Paul Zet

Reputation: 71

how do you create new lines in a textfield?

I have a model with a TextField ("notes"), and I want to add strings to it using variables, but separate the variables with a new line (\n)

aaa = "variable 1"
bbb = "variable 2"
ccc = "variable 3"

model.objects.create(id=id, notes=aaa + '\n' + bbb + '\n' + ccc)

However, when I render the field in the template as {{object.notes}}, the variables aren't separated at all.

Upvotes: 0

Views: 232

Answers (2)

Mohammad Ansari
Mohammad Ansari

Reputation: 1549

Try this:

Use < br /> instead of \n

Upvotes: 0

shacker
shacker

Reputation: 15371

\n represents newline in plain text, but you are asking about auto-creation of actual p and br HTML tags in the template layer. See the docs for linebreaks and linebreaksbr.

Both of these will handle automatic insertion of linebreaks or paragraphs in your templates.

Upvotes: 2

Related Questions