Reputation: 71
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
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