M. Dhaouadi
M. Dhaouadi

Reputation: 625

how to render <br /> to a new line in django template?

I am trying to render a message in a template using django. I used this code:

message = "hello <br /> how are you? " 
t = loader.get_template(template_html)
context = {"message":message}
return t.render(context)

The problem is that:

 I get hello <br /> how are you? 

in the template instead of a new line, how can I fix this?

Upvotes: 1

Views: 2686

Answers (1)

user2390182
user2390182

Reputation: 73450

You can either apply the safe filter in the template or mark message as safe in the view:

# template
{{ message|safe }}

or

# view
from django.utils.safestring import mark_safe
context = {"message": mark_safe(message)}

This will then render your message as html.

Upvotes: 5

Related Questions