Hans de Jong
Hans de Jong

Reputation: 2078

django string shows good in terminal but not in template

I am working on a message system but after i have sent a reply, my tempalte view of my mailbody gets put all on 1 line, while when i print the same string in terminal it works just fine.

The template:

<div>
To: {{ mail.to }}<br>
From: {{ mail.sender }}<br>
{{ mail.view_sent_at }}<br>
</div>

<div>
<br>
{{ mail.body }}
</div>

my reply body function: (to change the body to be shown as replay)

def reply_format(self):
    message = self.body
    message = "> " + message
    message = message.replace("\r\n", "\r\n> ")
    send_information = "\r\n\r\n> To: %s\r\n> From: %s\r\n> Date: %s\r\n>\r\n" % (self.to, self.sender, self.view_sent_at())
    message = send_information + message
    return message

now as example my mail body looks like this when i save it (and how it looks in my terminal after).

Send a reply

> To: admin
> From: admin
> Date: 12:14 02-06-2014
>
> This is a test.
> Need some extra lines
> Byebye

when i open it in my template it looks like:

To: admin
From: admin
12:14 02-06-2014

Send a reply > To: admin > From: admin > Date: 12:14 02-06-2014 > > This is a test. > Need some extra lines > Byebye 

Upvotes: 0

Views: 127

Answers (1)

Matt
Matt

Reputation: 10382

You can use the linebreaks filter in your template to convert the newlines to the appropriate HTML tags.

Upvotes: 2

Related Questions